This commit is contained in:
@@ -30,7 +30,7 @@ export class ApiError extends Error {
|
||||
code,
|
||||
requestId,
|
||||
details,
|
||||
rawMessage
|
||||
rawMessage,
|
||||
}: {
|
||||
message: string;
|
||||
status: number;
|
||||
@@ -59,7 +59,7 @@ function parseErrorPayload(data: unknown) {
|
||||
code: undefined as string | undefined,
|
||||
rawMessage: undefined as string | undefined,
|
||||
requestId: undefined as string | undefined,
|
||||
details: undefined as unknown
|
||||
details: undefined as unknown,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ export function createApiClient(config: CreateApiClientConfig) {
|
||||
baseUrl,
|
||||
resolveError = defaultResolveError,
|
||||
inferErrorCodeFromStatus,
|
||||
fetchImpl
|
||||
fetchImpl,
|
||||
} = config;
|
||||
|
||||
async function request<T>(path: string, options: RequestOptions = {}): Promise<T> {
|
||||
@@ -99,9 +99,9 @@ export function createApiClient(config: CreateApiClientConfig) {
|
||||
method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(token ? { Authorization: `Bearer ${token}` } : {})
|
||||
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
||||
},
|
||||
body: body ? JSON.stringify(body) : undefined
|
||||
body: body ? JSON.stringify(body) : undefined,
|
||||
});
|
||||
|
||||
const data = await response.json().catch(() => null);
|
||||
@@ -112,7 +112,7 @@ export function createApiClient(config: CreateApiClientConfig) {
|
||||
const message = resolveError({
|
||||
code,
|
||||
status: response.status,
|
||||
fallbackMessage: parsed.rawMessage
|
||||
fallbackMessage: parsed.rawMessage,
|
||||
});
|
||||
|
||||
throw new ApiError({
|
||||
@@ -121,7 +121,7 @@ export function createApiClient(config: CreateApiClientConfig) {
|
||||
code,
|
||||
requestId: parsed.requestId,
|
||||
details: parsed.details,
|
||||
rawMessage: parsed.rawMessage
|
||||
rawMessage: parsed.rawMessage,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -129,6 +129,6 @@ export function createApiClient(config: CreateApiClientConfig) {
|
||||
}
|
||||
|
||||
return {
|
||||
request
|
||||
request,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user