basic functionality...
This commit is contained in:
@@ -5,8 +5,8 @@ const httpMethodsThatMustNotHaveBody = [HttpMethod.GET]; // Head, Options
|
||||
|
||||
export class HttpRequestError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
public readonly status?: number,
|
||||
message: string,
|
||||
public readonly status?: number,
|
||||
public readonly statusText?: string,
|
||||
public readonly originalError?: unknown
|
||||
) {
|
||||
@@ -51,11 +51,7 @@ export class HttpRequests {
|
||||
const response = await fetch(requestPath, options);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new HttpRequestError(
|
||||
`HTTP error! status [${response.status}] ${response.statusText}`,
|
||||
response.status,
|
||||
response.statusText
|
||||
);
|
||||
throw new HttpRequestError(`HTTP error! status [${response.status}] ${response.statusText}`, response.status, response.statusText);
|
||||
}
|
||||
|
||||
const responseContentType = response.headers.get('content-type');
|
||||
@@ -69,14 +65,14 @@ export class HttpRequests {
|
||||
if (e instanceof HttpRequestError) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
if (e instanceof Error) {
|
||||
if (e.name === 'AbortError') {
|
||||
throw new HttpRequestError(`Request timeout after ${timeoutDuration}ms`, undefined, undefined, e);
|
||||
}
|
||||
throw new HttpRequestError(`Request failed: ${e.message}`, undefined, undefined, e);
|
||||
}
|
||||
|
||||
|
||||
throw new HttpRequestError(`Unknown request error: ${String(e)}`, undefined, undefined, e);
|
||||
} finally {
|
||||
globalThis.clearTimeout(requestTimeoutId);
|
||||
|
||||
Reference in New Issue
Block a user