From 61e8266e371fa37df753caf25f14804989a810a6 Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle <patrizio@bekerle.com> Date: Wed, 17 Feb 2021 07:45:02 +0100 Subject: [PATCH] Remove unused handleXhrError and handleFetchError functions --- packages/common/error.js | 85 ---------------------------------------- 1 file changed, 85 deletions(-) diff --git a/packages/common/error.js b/packages/common/error.js index fb7f2b63..353a4a17 100644 --- a/packages/common/error.js +++ b/packages/common/error.js @@ -1,91 +1,6 @@ import {send as notify} from './notification'; import {i18n} from "./i18n"; -/** - * Error handling for XHR errors - * - * @param jqXHR - * @param textStatus - * @param errorThrown - * @param icon - */ -export const handleXhrError = (jqXHR, textStatus, errorThrown, icon = "sad") => { - // return if user aborted the request - if (textStatus === "abort") { - return; - } - - let body; - - if (jqXHR.responseJSON !== undefined && jqXHR.responseJSON["hydra:description"] !== undefined) { - // response is a JSON-LD - body = jqXHR.responseJSON["hydra:description"]; - } else if (jqXHR.responseJSON !== undefined && jqXHR.responseJSON['detail'] !== undefined) { - // response is a plain JSON - body = jqXHR.responseJSON['detail']; - } else { - // no description available - body = textStatus; - } - - // if the server is not reachable at all - if (jqXHR.status === 0) { - body = i18n.t('error.connection-to-server-refused'); - } - - notify({ - "summary": i18n.t('error.summary'), - "body": escapeHTML(stripHTML(body)), - "icon": icon, - "type": "danger", - }); -}; - -/** - * Error handling for fetch errors - * - * @param error - * @param summary - * @param icon - */ -export const handleFetchError = async (error, summary = "", icon = "sad") => { - // return if user aborted the request - if (error.name === "AbortError") { - return; - } - - let body; - - try { - await error.json().then((json) => { - if (json["hydra:description"] !== undefined) { - // response is a JSON-LD and possibly also contains HTML! - body = json["hydra:description"]; - } else if (json['detail'] !== undefined) { - // response is a plain JSON - body = json['detail']; - } else { - // no description available - body = error.statusText; - } - }).catch(() => { - body = error.statusText !== undefined ? error.statusText : error; - }); - } catch (e) { - // a TypeError means the connection to the server was refused most of the times - if (error.name === "TypeError") { - body = error.message !== "" ? error.message : i18n.t('error.connection-to-server-refused'); - } - } - - notify({ - "summary": summary === "" ? i18n.t('error.summary') : summary, - "body": escapeHTML(stripHTML(body)), - "icon": icon, - "type": "danger", - }); -}; - /** * Escapes html * -- GitLab