diff options
author | Michael C <[email protected]> | 2022-03-10 02:31:19 -0500 |
---|---|---|
committer | Michael C <[email protected]> | 2022-03-10 02:31:19 -0500 |
commit | 7c747e65664d7225010abc25739e6f11e9a1c848 (patch) | |
tree | 5b1044dd0216f8917d3fad878854e10c05edd8c7 | |
parent | d02aab4ba35d224d10a83644e487880da2a7a8dd (diff) | |
download | SponsorBlock-7c747e65664d7225010abc25739e6f11e9a1c848.tar.gz SponsorBlock-7c747e65664d7225010abc25739e6f11e9a1c848.zip |
custom error handler for 5xx
-rw-r--r-- | src/utils/genericUtils.ts | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/utils/genericUtils.ts b/src/utils/genericUtils.ts index 3451c738..bd27de8c 100644 --- a/src/utils/genericUtils.ts +++ b/src/utils/genericUtils.ts @@ -28,20 +28,18 @@ async function wait<T>(condition: () => T | false, timeout = 5000, check = 100): * @returns {string} errorMessage */ function getErrorMessage(statusCode: number, responseText: string): string { - let errorMessage = ""; const postFix = (responseText ? "\n\n" + responseText : ""); - - if([400, 429, 409, 502, 503, 0].includes(statusCode)) { - //treat them the same + // display response body for 4xx + if([400, 429, 409, 0].includes(statusCode)) { + return chrome.i18n.getMessage(statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + statusCode + postFix; + } else if (statusCode >= 500 && statusCode <= 599) { + // 503 == 502 if (statusCode == 503) statusCode = 502; - - errorMessage = chrome.i18n.getMessage(statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + statusCode - + "\n\n" + chrome.i18n.getMessage("statusReminder"); + return chrome.i18n.getMessage(statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + statusCode + + "\n\n" + chrome.i18n.getMessage("statusReminder"); } else { - errorMessage = chrome.i18n.getMessage("connectionError") + statusCode; + return chrome.i18n.getMessage("connectionError") + statusCode + postFix; } - - return errorMessage + postFix; } /* Gets percieved luminance of a color */ |