Move more funcs to shared lib

This commit is contained in:
Ajay
2023-05-09 22:12:15 -04:00
parent 33d098d78a
commit 92fabdf37a
7 changed files with 18 additions and 41 deletions

View File

@@ -1,24 +1,3 @@
/**
* Gets the error message in a nice string
*
* @param {int} statusCode
* @returns {string} errorMessage
*/
function getErrorMessage(statusCode: number, responseText: string): string {
const postFix = ((responseText && !(responseText.includes(`cf-wrapper`) || responseText.includes("<!DOCTYPE html>"))) ? "\n\n" + responseText : "");
// 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;
return chrome.i18n.getMessage(statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + statusCode
+ "\n\n" + chrome.i18n.getMessage("statusReminder");
} else {
return chrome.i18n.getMessage("connectionError") + statusCode + postFix;
}
}
/* Gets percieved luminance of a color */
function getLuminance(color: string): number {
const {r, g, b} = hexToRgb(color);
@@ -50,7 +29,6 @@ function indexesOf<T>(array: T[], value: T): number[] {
}
export const GenericUtils = {
getErrorMessage,
getLuminance,
indexesOf
}