diff --git a/package.json b/package.json index dc10612..e373847 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,7 @@ "fetch-retry": "^5.0.6", "http-status-codes": "^2.3.0", "openapi-fetch": "^0.8.2", - "p-queue-compat": "^1.0.225", + "p-queue-compat": "1.0.225", "yaml": "^2.3.3" }, "lint-staged": { diff --git a/src/errors.ts b/src/errors.ts index bf47890..a31e268 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -1,4 +1,6 @@ -import { ApiError } from './api/client.js'; +import { AbortError as _AbortError } from 'p-queue-compat'; + +import type { ApiError } from './api/client.js'; export class BaseError extends Error {} @@ -22,3 +24,8 @@ export class HttpError extends RequestError implements ApiError { this.extensions = error.extensions; } } + +// cjs compilation bug +export const AbortError: typeof _AbortError = _AbortError + ? _AbortError + : class AbortError extends Error {}; diff --git a/src/utils/errors.ts b/src/utils/errors.ts index 043435e..1383460 100644 --- a/src/utils/errors.ts +++ b/src/utils/errors.ts @@ -1,11 +1,18 @@ import { FetchResponse } from 'openapi-fetch'; -import { AbortError } from 'p-queue-compat'; -AbortError.prototype.name = 'AbortError'; -import { HttpError, InternalError, NetworkError } from '../errors.js'; +import { + HttpError, + InternalError, + NetworkError, + AbortError, +} from '../errors.js'; -function isAbortError(err: unknown): err is DOMException { - return Boolean(err && err instanceof Error && err.name === 'AbortError'); +export function isAbortError(err: unknown): err is DOMException { + return Boolean( + err && + err instanceof Error && + (err.name === 'AbortError' || err instanceof AbortError), + ); } const ServiceUnavailableErrorCodes = new Set([ diff --git a/yarn.lock b/yarn.lock index 916f058..635d0c4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -695,7 +695,7 @@ __metadata: msw: ^1.3.2 openapi-fetch: ^0.8.2 openapi-typescript: ^6.7.4 - p-queue-compat: ^1.0.225 + p-queue-compat: 1.0.225 pinst: ^3.0.0 prettier: ^3.0.3 ts-node: ^10.9.1 @@ -5424,7 +5424,7 @@ __metadata: languageName: node linkType: hard -"p-queue-compat@npm:^1.0.225": +"p-queue-compat@npm:1.0.225": version: 1.0.225 resolution: "p-queue-compat@npm:1.0.225" dependencies: