Skip to content

Commit

Permalink
Rename types that refer to RequestCallback
Browse files Browse the repository at this point in the history
We removed RequestCallback in d0568d7.
  • Loading branch information
lawrence-forooghian committed Feb 15, 2024
1 parent d0568d7 commit 2cf5a6b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 33 deletions.
6 changes: 3 additions & 3 deletions src/common/lib/client/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Logger from '../util/logger';
import * as Utils from '../util/utils';
import Multicaster, { MulticasterInstance } from '../util/multicaster';
import ErrorInfo, { IPartialErrorInfo } from '../types/errorinfo';
import { RequestCallbackError, RequestParams, RequestResult } from '../../types/http';
import { RequestResultError, RequestParams, RequestResult } from '../../types/http';
import * as API from '../../../../ably';
import BaseClient from './baseclient';
import BaseRealtime from './baserealtime';
Expand Down Expand Up @@ -395,7 +395,7 @@ class Auth {
let tokenRequestCallback: (
data: API.TokenParams,
callback: (
error: API.ErrorInfo | RequestCallbackError | string | null,
error: API.ErrorInfo | RequestResultError | string | null,
tokenRequestOrDetails: API.TokenDetails | API.TokenRequest | string | null,
contentType?: string
) => void
Expand Down Expand Up @@ -566,7 +566,7 @@ class Auth {

const tokenRequest = (
signedTokenParams: Record<string, any>,
tokenCb: (err: RequestCallbackError | null, tokenResponse?: API.TokenDetails | string, unpacked?: boolean) => void
tokenCb: (err: RequestResultError | null, tokenResponse?: API.TokenDetails | string, unpacked?: boolean) => void
) => {
const keyName = signedTokenParams.keyName,
path = '/keys/' + keyName + '/requestToken',
Expand Down
8 changes: 4 additions & 4 deletions src/common/lib/client/paginatedresource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import Logger from '../util/logger';
import Resource, { ResourceResult } from './resource';
import { IPartialErrorInfo } from '../types/errorinfo';
import BaseClient from './baseclient';
import { RequestBody, RequestCallbackHeaders } from 'common/types/http';
import { RequestBody, ResponseHeaders } from 'common/types/http';

export type BodyHandler = (body: unknown, headers: RequestCallbackHeaders, unpacked?: boolean) => Promise<any>;
export type BodyHandler = (body: unknown, headers: ResponseHeaders, unpacked?: boolean) => Promise<any>;

function getRelParams(linkUrl: string) {
const urlMatch = linkUrl.match(/^\.\/(\w+)\?(.*)$/);
Expand Down Expand Up @@ -176,14 +176,14 @@ export class PaginatedResult<T> {
export class HttpPaginatedResponse<T> extends PaginatedResult<T> {
statusCode: number;
success: boolean;
headers: RequestCallbackHeaders;
headers: ResponseHeaders;
errorCode?: number | null;
errorMessage?: string | null;

constructor(
resource: PaginatedResource,
items: T[],
headers: RequestCallbackHeaders,
headers: ResponseHeaders,
statusCode: number,
relParams: any,
err: IPartialErrorInfo | null
Expand Down
11 changes: 3 additions & 8 deletions src/common/lib/client/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@ import HttpMethods from '../../constants/HttpMethods';
import ErrorInfo, { IPartialErrorInfo, PartialErrorInfo } from '../types/errorinfo';
import BaseClient from './baseclient';
import { MsgPack } from 'common/types/msgpack';
import {
RequestBody,
RequestCallbackHeaders,
appendingParams as urlFromPathAndParams,
paramString,
} from 'common/types/http';
import { RequestBody, ResponseHeaders, appendingParams as urlFromPathAndParams, paramString } from 'common/types/http';

async function withAuthDetails<T>(
client: BaseClient,
headers: RequestCallbackHeaders | undefined,
headers: ResponseHeaders | undefined,
params: Record<string, any>,
opCallback: Function
): Promise<ResourceResult<T>> {
Expand Down Expand Up @@ -102,7 +97,7 @@ function logResult<T>(result: ResourceResult<T>, method: HttpMethods, path: stri

export interface ResourceResponse<T> {
body?: T;
headers?: RequestCallbackHeaders;
headers?: ResponseHeaders;
unpacked?: boolean;
statusCode?: number;
}
Expand Down
10 changes: 5 additions & 5 deletions src/common/types/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import Logger from 'common/lib/util/logger';
import * as Utils from 'common/lib/util/utils';

export type PathParameter = string | ((host: string) => string);
export type RequestCallbackHeaders = Partial<Record<string, string | string[]>>;
export type RequestCallbackError = ErrnoException | IPartialErrorInfo;
export type ResponseHeaders = Partial<Record<string, string | string[]>>;
export type RequestResultError = ErrnoException | IPartialErrorInfo;

/**
* The `body`, `headers`, `unpacked`, and `statusCode` properties of a `RequestResult` may be populated even if its `error` property is non-null.
*/
export type RequestResult = {
error: RequestCallbackError | null;
error: RequestResultError | null;
body?: unknown;
headers?: RequestCallbackHeaders;
headers?: ResponseHeaders;
unpacked?: boolean;
statusCode?: number;
};
Expand Down Expand Up @@ -55,7 +55,7 @@ export interface IPlatformHttp {
/**
* @param error An error from the {@link RequestResult.error} property of a result returned by {@link doUri}.
*/
shouldFallback(error: RequestCallbackError): boolean;
shouldFallback(error: RequestResultError): boolean;
}

export function paramString(params: Record<string, any> | null) {
Expand Down
4 changes: 2 additions & 2 deletions src/platform/nodejs/lib/util/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ErrnoException,
RequestBody,
IPlatformHttpStatic,
RequestCallbackError,
RequestResultError,
RequestParams,
RequestResult,
} from '../../../../common/types/http';
Expand Down Expand Up @@ -158,7 +158,7 @@ const Http: IPlatformHttpStatic = class {
return !error && (body as Buffer | string)?.toString().trim() === 'yes';
};

shouldFallback(err: RequestCallbackError) {
shouldFallback(err: RequestResultError) {
const { code, statusCode } = err as ErrnoException;
return (
code === 'ENETUNREACH' ||
Expand Down
4 changes: 2 additions & 2 deletions src/platform/web/lib/http/http.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Platform from 'common/platform';
import Defaults from 'common/lib/util/defaults';
import ErrorInfo, { PartialErrorInfo } from 'common/lib/types/errorinfo';
import { RequestBody, RequestCallbackError, RequestParams, RequestResult } from 'common/types/http';
import { RequestBody, RequestResultError, RequestParams, RequestResult } from 'common/types/http';
import HttpMethods from 'common/constants/HttpMethods';
import BaseClient from 'common/lib/client/baseclient';
import XHRStates from 'common/constants/XHRStates';
Expand Down Expand Up @@ -158,7 +158,7 @@ const Http = class {
supportsAuthHeaders = false;
supportsLinkHeaders = false;

shouldFallback(errorInfo: RequestCallbackError) {
shouldFallback(errorInfo: RequestResultError) {
const statusCode = errorInfo.statusCode as number;
/* 400 + no code = a generic xhr onerror. Browser doesn't give us enough
* detail to know whether it's fallback-fixable, but it may be (eg if a
Expand Down
12 changes: 3 additions & 9 deletions src/platform/web/lib/http/request/fetchrequest.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import HttpMethods from 'common/constants/HttpMethods';
import BaseClient from 'common/lib/client/baseclient';
import ErrorInfo, { PartialErrorInfo } from 'common/lib/types/errorinfo';
import {
RequestBody,
RequestCallbackError,
RequestCallbackHeaders,
RequestParams,
RequestResult,
} from 'common/types/http';
import { RequestBody, RequestResultError, ResponseHeaders, RequestParams, RequestResult } from 'common/types/http';
import Platform from 'common/platform';
import Defaults from 'common/lib/util/defaults';
import * as Utils from 'common/lib/util/utils';
Expand All @@ -23,7 +17,7 @@ function getAblyError(responseBody: unknown, headers: Headers) {
}

function convertHeaders(headers: Headers) {
const result: RequestCallbackHeaders = {};
const result: ResponseHeaders = {};

headers.forEach((value, key) => {
result[key] = value;
Expand Down Expand Up @@ -100,7 +94,7 @@ export default async function fetchRequest(
}
} catch (error) {
clearTimeout(timeout!);
return { error: error as RequestCallbackError };
return { error: error as RequestResultError };
}
})();

Expand Down

0 comments on commit 2cf5a6b

Please sign in to comment.