Skip to content

Commit c5304f4

Browse files
committed
fix(subscribe): fix / revert fetch TypeError handling
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).
1 parent 0beda2c commit c5304f4

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

dist/web/pubnub.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,7 @@
410410

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

413-
if (typeof undefined$1 === "function" && undefined$1.amd)
414-
undefined$1("cbor/cbor", obj);
415-
else if (module.exports)
413+
if (module.exports)
416414
module.exports = obj;
417415
else if (!global.CBOR)
418416
global.CBOR = obj;
@@ -889,7 +887,7 @@
889887
return Object.assign(Object.assign({}, errorPayload), { statusCode: errorPayload.statusCode, category: StatusCategory$1.PNValidationErrorCategory, error: true });
890888
}
891889
function createValidationError(message, statusCode) {
892-
return createError(Object.assign({ message }, (statusCode !== undefined ? { statusCode } : {})));
890+
return createError(Object.assign({ message }, ({})));
893891
}
894892

895893
/*eslint-disable */
@@ -2839,10 +2837,7 @@
28392837
message = 'Network issues';
28402838
}
28412839
else if (errorName === 'TypeError') {
2842-
if (message.indexOf('Load failed') !== -1 || message.indexOf('Failed to fetch') != -1)
2843-
category = StatusCategory$1.PNTimeoutCategory;
2844-
else
2845-
category = StatusCategory$1.PNBadRequestCategory;
2840+
category = StatusCategory$1.PNBadRequestCategory;
28462841
}
28472842
else if (errorName === 'FetchError') {
28482843
const errorCode = error.code;

dist/web/pubnub.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/errors/pubnub-api-error.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ export class PubNubAPIError extends Error {
5858
category = StatusCategory.PNNetworkIssuesCategory;
5959
message = 'Network issues';
6060
} else if (errorName === 'TypeError') {
61-
if (message.indexOf('Load failed') !== -1 || message.indexOf('Failed to fetch') != -1)
62-
category = StatusCategory.PNTimeoutCategory;
63-
else category = StatusCategory.PNBadRequestCategory;
61+
category = StatusCategory.PNBadRequestCategory;
6462
} else if (errorName === 'FetchError') {
6563
const errorCode = (error as Record<string, string>).code;
6664

0 commit comments

Comments
 (0)