Skip to content

Commit

Permalink
fix: cjs - missing AbortError export
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas2D committed Aug 29, 2024
1 parent 0a7d2b1 commit 733a4dc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
9 changes: 8 additions & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
@@ -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 {}

Expand All @@ -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 {};
17 changes: 12 additions & 5 deletions src/utils/errors.ts
Original file line number Diff line number Diff line change
@@ -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([
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 733a4dc

Please sign in to comment.