basic functionality...

This commit is contained in:
2025-08-17 10:36:57 -04:00
parent 1c032da3df
commit 6a40cfa568
13 changed files with 227 additions and 106 deletions

View File

@@ -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);