Skip to content

Commit

Permalink
fix(subscribe): fix / revert fetch TypeError handling
Browse files Browse the repository at this point in the history
Revert fix created to handle browser timeouts (not gracefully). The Web Fetch API doesn't have
descriptive error information, and it sends `TypeError` for both cases when connection closed
by browser or network issue (blocked domain).
  • Loading branch information
parfeon committed Oct 25, 2024
1 parent 0beda2c commit c5304f4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
11 changes: 3 additions & 8 deletions dist/web/pubnub.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,7 @@

var obj = { encode: encode, decode: decode };

if (typeof undefined$1 === "function" && undefined$1.amd)
undefined$1("cbor/cbor", obj);
else if (module.exports)
if (module.exports)
module.exports = obj;
else if (!global.CBOR)
global.CBOR = obj;
Expand Down Expand Up @@ -889,7 +887,7 @@
return Object.assign(Object.assign({}, errorPayload), { statusCode: errorPayload.statusCode, category: StatusCategory$1.PNValidationErrorCategory, error: true });
}
function createValidationError(message, statusCode) {
return createError(Object.assign({ message }, (statusCode !== undefined ? { statusCode } : {})));
return createError(Object.assign({ message }, ({})));
}

/*eslint-disable */
Expand Down Expand Up @@ -2839,10 +2837,7 @@
message = 'Network issues';
}
else if (errorName === 'TypeError') {
if (message.indexOf('Load failed') !== -1 || message.indexOf('Failed to fetch') != -1)
category = StatusCategory$1.PNTimeoutCategory;
else
category = StatusCategory$1.PNBadRequestCategory;
category = StatusCategory$1.PNBadRequestCategory;
}
else if (errorName === 'FetchError') {
const errorCode = error.code;
Expand Down
2 changes: 1 addition & 1 deletion dist/web/pubnub.min.js

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions src/errors/pubnub-api-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ export class PubNubAPIError extends Error {
category = StatusCategory.PNNetworkIssuesCategory;
message = 'Network issues';
} else if (errorName === 'TypeError') {
if (message.indexOf('Load failed') !== -1 || message.indexOf('Failed to fetch') != -1)
category = StatusCategory.PNTimeoutCategory;
else category = StatusCategory.PNBadRequestCategory;
category = StatusCategory.PNBadRequestCategory;
} else if (errorName === 'FetchError') {
const errorCode = (error as Record<string, string>).code;

Expand Down

0 comments on commit c5304f4

Please sign in to comment.