From 765031e51042d0a4722dcb7cdcd78d8309eb2f9a Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Thu, 12 Sep 2024 13:46:05 +0200 Subject: [PATCH] [#550] Localize frontend errors messages. --- public/locales/cs/translation.json | 102 +++++++++++++++++++--- public/locales/en/translation.json | 95 +++++++++++++++++--- src/services/componentService.tsx | 44 ++++------ src/services/documentService.tsx | 6 +- src/services/failureModeService.tsx | 30 +++---- src/services/failureModesRowService.tsx | 3 +- src/services/failureModesTableService.tsx | 18 ++-- src/services/faultEventService.tsx | 25 ++---- src/services/faultTreeService.tsx | 39 +++------ src/services/functionService.tsx | 24 ++--- src/services/mitigationService.tsx | 2 +- src/services/systemService.tsx | 36 ++++---- src/services/userService.tsx | 9 +- src/services/utils/responseUtils.tsx | 39 +++++---- 14 files changed, 278 insertions(+), 194 deletions(-) diff --git a/public/locales/cs/translation.json b/public/locales/cs/translation.json index e3ac2541..75dc5f61 100644 --- a/public/locales/cs/translation.json +++ b/public/locales/cs/translation.json @@ -122,28 +122,102 @@ "save": "Uložit", "discard": "Zahodit" }, - "errors": { + + "error": { + "default": "Došlo k chybě", + "faultEvent": { + "findAll": "Nepodařilo se najít události závad. {{error}}", + "update": "Nepodařilo se aktualizovat událost závady. {{error}}", + "remove": "Nepodařilo se odstranit událost závady. {{error}}", + "create": "Nepodařilo se vytvořit událost. {{error}}", + "updateRectangle": "Nepodařilo se aktualizovat obdélník. {{error}}", + "getFailureMode": "Nepodařilo se načíst režim selhání události. {{error}}", + "deleteFailureMode": "Nepodařilo se smazat režim selhání události. {{error}}", + "updateChildrenSequence": "Nepodařilo se aktualizovat pořadí dětí. {{error}}", + "getRootReusable": "Nepodařilo se najít znovu použitelné události závady. {{error}}", + "getAllReusable": "Nepodařilo se najít všechny znovu použitelné události závady. {{error}}" + }, "faultTree": { "rootEvent": { - "deleteViolation": "Kořenová událost stromu nesmí být smazána!" - } + "deleteViolation": "Kořenová událost stromu nemůže být smazána!" + }, + "intermediateEventAsLeaf": "Mezilehlá událost nemůže být na konci cesty!", + "findAll": "Nepodařilo se načíst stromy závad. {{error}}", + "findAllWithFilters": "Nepodařilo se načíst stromy závad s filtry. {{error}}", + "find": "Nepodařilo se najít strom závad. {{error}}", + "create": "Nepodařilo se vytvořit strom závad. {{error}}", + "update": "Nepodařilo se aktualizovat strom závad. {{error}}", + "remove": "Nepodařilo se odstranit strom závad. {{error}}", + "getTreePaths": "Nepodařilo se načíst cesty stromu. {{error}}", + "getTreePathsAggregate": "Nepodařilo se načíst všechny cesty stromu. {{error}}", + "calculateCutSets": "Nepodařilo se vypočítat řezové množiny stromu závad. {{error}}" + }, + "function": { + "findAll": "Nepodařilo se načíst funkce. {{error}}", + "addRequiredFunction": "Nepodařilo se přidat požadovanou funkci. {{error}}", + "update": "Nepodařilo se aktualizovat funkci. {{error}}", + "getImpairedBehaviour": "Nepodařilo se získat narušené chování. {{error}}", + "create": "Nepodařilo se vytvořit funkci. {{error}}", + "add": "Nepodařilo se přidat existující funkci. {{error}}", + "remove": "Nepodařilo se odstranit funkci. {{error}}" + }, + "mitigation": { + "update": "Nepodařilo se aktualizovat zmírnění. {{error}}" + }, + "system": { + "findAll": "Nepodařilo se načíst systémy. {{error}}", + "find": "Nepodařilo se najít systém. {{error}}", + "create": "Nepodařilo se vytvořit systém. {{error}}", + "update": "Nepodařilo se aktualizovat systém. {{error}}", + "remove": "Nepodařilo se odstranit systém. {{error}}", + "updateFilter": "Nepodařilo se aktualizovat filtr provozních dat. {{error}}" + }, + "component": { + "mergeComponent": "Nepodařilo se sloučit komponenty. {{error}}", + "findAll": "Nepodařilo se načíst komponenty. {{error}}", + "find": "Nepodařilo se načíst komponentu. {{error}}", + "create": "Nepodařilo se vytvořit komponentu. {{error}}", + "update": "Nepodařilo se aktualizovat komponentu. {{error}}", + "linkComponent": "Nepodařilo se propojit komponenty. {{error}}", + "unlinkComponent": "Nepodařilo se odpojit komponenty. {{error}}", + "remove": "Nepodařilo se odstranit komponentu. {{error}}", + "add": "Nepodařilo se přidat komponentu. {{error}}" + }, + "failureMode": { + "findAll": "Nepodařilo se načíst režimy selhání. {{error}}", + "find": "Nepodařilo se načíst režim selhání. {{error}}", + "create": "Nepodařilo se vytvořit režim selhání. {{error}}", + "update": "Nepodařilo se aktualizovat režim selhání. {{error}}", + "add": "Nepodařilo se přidat režim selhání. {{error}}", + "remove": "Nepodařilo se odstranit režim selhání. {{error}}" + }, + "failureModesRow": { + "update": "Nepodařilo se aktualizovat řádek režimů selhání rpn. {{error}}" + }, + "failureModesTable": { + "findAll": "Nepodařilo se načíst tabulky režimů selhání. {{error}}", + "update": "Nepodařilo se aktualizovat tabulky režimů selhání. {{error}}", + "create": "Nepodařilo se vytvořit tabulku režimů selhání. {{error}}", + "remove": "Nepodařilo se odstranit tabulky režimů selhání. {{error}}", + "computeTableData": "Nepodařilo se načíst data tabulky režimů selhání. {{error}}", + "export": "Nepodařilo se exportovat tabulku režimů selhání. {{error}}", + "createAggregate": "Nepodařilo se vytvořit agregátní tabulku režimů selhání. {{error}}" + }, + "document": { + "import": "Nepodařilo se importovat dokument. {{error}}", + "findAll": "Nepodařilo se načíst dokumenty. {{error}}" }, "user": { "update": { "uriMismatch": "URI pro aktualizaci uživatele se neshoduje s aktuálním uživatelem!", - "incorrectOldPassword": "Staré heslo je nesprávné!" + "incorrectOldPassword": "Stará heslo je nesprávné!" }, "impersonation": { - "adminImpersonation": "Nelze se vydávat za správce." - } - }, - "faultTreeTraversal": { - "intermediateEventAsLeaf": "Mezilehlá událost nesmí být na konci cesty!" - }, - "externalService": { - "configuration": { - "failureRateServiceNotSet": "Konfigurační parametr operationalFailureRateService není nastaven." - } + "adminImpersonation": "Nelze se vydávat za administrátora." + }, + "register": "Registrace se nezdařila. {{error}}", + "login": "Přihlášení se nezdařilo. {{error}}", + "password": "Změna hesla se nezdařila. {{error}}" } } } diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index f308cb43..bb9a8244 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -122,11 +122,89 @@ "save": "Save", "discard": "Discard" }, - "errors": { + "error": { + "default": "An error occurred", + "faultEvent": { + "findAll": "Failed to find fault events. {{error}}", + "update": "Failed to update fault event. {{error}}", + "remove": "Failed to remove fault event. {{error}}", + "create": "Failed to create event. {{error}}", + "updateRectangle": "Failed to update rectangle. {{error}}", + "getFailureMode": "Failed to load event failure mode. {{error}}", + "deleteFailureMode": "Failed to delete event failure mode. {{error}}", + "updateChildrenSequence": "Failed to update children sequence. {{error}}", + "getRootReusable": "Failed to find reusable fault events. {{error}}", + "getAllReusable": "Failed to find all reusable fault events. {{error}}" + }, "faultTree": { "rootEvent": { "deleteViolation": "Root event of tree mustn't be deleted!" - } + }, + "intermediateEventAsLeaf": "Intermediate event must not be the end of the path!", + "findAll": "Failed to load fault trees. {{error}}", + "findAllWithFilters": "Failed to load fault trees with filters. {{error}}", + "find": "Failed to find fault tree. {{error}}", + "create": "Failed to create fault tree. {{error}}", + "update": "Failed to update fault tree. {{error}}", + "remove": "Failed to remove fault tree. {{error}}", + "getTreePaths": "Failed to load tree paths. {{error}}", + "getTreePathsAggregate": "Failed to load all tree paths. {{error}}", + "calculateCutSets": "Failed to calculate cutsets of fault tree. {{error}}" + }, + "function": { + "findAll": "Failed to load functions. {{error}}", + "addRequiredFunction": "Failed to add required Function. {{error}}", + "update": "Failed to update function. {{error}}", + "getImpairedBehaviour": "Failed to get impaired behaviors. {{error}}", + "create": "Failed to create function. {{error}}", + "add": "Failed to add existing function. {{error}}", + "remove": "Failed to remove function. {{error}}" + }, + "mitigation": { + "update": "Failed to update mitigation. {{error}}" + }, + "system": { + "findAll": "Failed to load systems. {{error}}", + "find": "Failed to find system. {{error}}", + "create": "Failed to create system. {{error}}", + "update": "Failed to update system. {{error}}", + "remove": "Failed to remove system. {{error}}", + "updateFilter": "Failed to operational data filter. {{error}}" + }, + "component": { + "mergeComponent": "Failed to merge components. {{error}}", + "findAll": "Failed to load components. {{error}}", + "find": "Failed to load component. {{error}}", + "create": "Failed to create component. {{error}}", + "update": "Failed to update component. {{error}}", + "linkComponent": "Failed to link components. {{error}}", + "unlinkComponent": "Failed to unlink components. {{error}}", + "remove": "Failed to remove component. {{error}}", + "add": "Failed to add component. {{error}}" + }, + "failureMode": { + "findAll": "Failed to load failure modes. {{error}}", + "find": "Failed to load failure mode. {{error}}", + "create": "Failed to create failure mode. {{error}}", + "update": "Failed to update failure mode. {{error}}", + "add": "Failed to add failure mode. {{error}}", + "remove": "Failed to remove failure mode. {{error}}" + }, + "failureModesRow": { + "update": "Failed to update failure modes row rpn. {{error}}" + }, + "failureModesTable": { + "findAll": "Failed to load failure modes tables. {{error}}", + "update": "Failed to update failure modes tables. {{error}}", + "create": "Failed to create failure modes table. {{error}}", + "remove": "Failed to remove failure modes tables. {{error}}", + "computeTableData": "Failed to load failure modes table data. {{error}}", + "export": "Failed to export table data. {{error}}", + "createAggregate": "Failed to create failure modes aggregate table. {{error}}" + }, + "document": { + "import": "Failed to import document. {{error}}", + "findAll": "Failed to load documents. {{error}}" }, "user": { "update": { @@ -135,15 +213,10 @@ }, "impersonation": { "adminImpersonation": "Cannot impersonate admin." - } - }, - "faultTreeTraversal": { - "intermediateEventAsLeaf": "Intermediate event must not be the end of the path!" - }, - "externalService": { - "configuration": { - "failureRateServiceNotSet": "Configuration parameter operationalFailureRateService not set." - } + }, + "register": "Registration failed. {{error}}", + "login": "Login failed. {{error}}", + "passwordChange": "Password change failed. {{error}}" } } } diff --git a/src/services/componentService.tsx b/src/services/componentService.tsx index b2194d5e..55c47044 100644 --- a/src/services/componentService.tsx +++ b/src/services/componentService.tsx @@ -27,8 +27,7 @@ export async function mergeComponents(iri: string, iri2: string): Promise return new Promise((resolve) => resolve()); } catch (e) { console.log("Component Service - Failed to call /mergeComponents"); - const defaultMessage = "Failed to merge components"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.component.mergeComponent"))); } } @@ -41,8 +40,7 @@ export const findAll = async (): Promise => { return JsonLdUtils.compactAndResolveReferencesAsArray(response.data, CONTEXT); } catch (e) { console.log("Component Service - Failed to call /findAll"); - const defaultMessage = "Failed to load components"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.component.findAll"))); } }; @@ -57,8 +55,7 @@ export const create = async (component: CreateComponent): Promise => return JsonLdUtils.compactAndResolveReferences(response.data, CONTEXT); } catch (e) { console.log("Component Service - Failed to call /create"); - const defaultMessage = "Failed to create component"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.component.create"))); } }; @@ -72,7 +69,7 @@ export const update = async (componentUpdate: UpdateComponent): Promise reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.component.update"))); } }; @@ -86,8 +83,7 @@ export const functions = async (componentUri: string): Promise => { return JsonLdUtils.compactAndResolveReferencesAsArray(response.data, FUNCTION_CONTEXT); } catch (e) { console.log("Component Service - Failed to call /functions"); - const defaultMessage = "Failed to load functions"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.functions.findAll"))); } }; @@ -101,8 +97,7 @@ export const failureModes = async (componentUri: string): Promise return JsonLdUtils.compactAndResolveReferencesAsArray(response.data, FAILURE_MODE_CONTEXT); } catch (e) { console.log("Component Service - Failed to call /failureModes"); - const defaultMessage = "Failed to load failure modes"; - return new Promise((_resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((_resolve, reject) => reject(handleServerError(e, "error.failureMode.findAll"))); } }; @@ -121,8 +116,7 @@ export const addFunction = async (componentUri: string, f: Function): Promise(response.data, CONTEXT); } catch (e) { console.log("Component Service - Failed to call create function"); - const defaultMessage = "Failed to create function"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.function.create"))); } }; @@ -143,8 +137,7 @@ export const addFunctionByURI = async (componentUri: string, functionUri: string } catch (e) { console.log(e); console.log("Component Service - Failed to call add function by URI"); - const defaultMessage = "Failed to add existing function"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.function.add"))); } }; @@ -159,8 +152,7 @@ export const removeFunction = async (componentIri: string, functionIri: string) return new Promise((resolve) => resolve()); } catch (e) { console.log("Component Service - Failed to call /removeFunction"); - const defaultMessage = "Failed to remove function"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.function.remove"))); } }; @@ -176,8 +168,7 @@ export const linkComponent = async (componentUri: string, linkUri: string): Prom return JsonLdUtils.compactAndResolveReferences(response.data, CONTEXT); } catch (e) { console.log("Component Service - Failed to call /linkComponent"); - const defaultMessage = "Failed to link components"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.component.linkComponent"))); } }; @@ -192,8 +183,7 @@ export const unlinkComponent = async (componentUri: string): Promise => { return new Promise((resolve) => resolve()); } catch (e) { console.log("Component Service - Failed to call /unlinkComponent"); - const defaultMessage = "Failed to unlink components"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.component.unlinkComponent"))); } }; @@ -207,8 +197,7 @@ export const remove = async (componentIri: string): Promise => { return new Promise((resolve) => resolve()); } catch (e) { console.log("Component Service - Failed to call /remove"); - const defaultMessage = "Failed to remove component"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.component.remove"))); } }; @@ -239,8 +228,7 @@ export const addFailureModeByURI = async (componentUri: string, failureModeUri: return new Promise((resolve) => resolve()); } catch (e) { console.log("Component Service - Failed to call add failure mode by URI"); - const defaultMessage = "Failed to add existing failure mode"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureMode.add"))); } }; @@ -265,8 +253,7 @@ export const addFailureMode = async (componentUri: string, failureMode: FailureM } catch (e) { console.log("Component Service - Failed to call create failure mode"); console.log(e); - const defaultMessage = "Failed to create failure mode"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureMode.create"))); } }; @@ -281,7 +268,6 @@ export const removeFailureMode = async (componentIri: string, failureModeUri: st return new Promise((resolve) => resolve()); } catch (e) { console.log("Component Service - Failed to call /removeFailureMode"); - const defaultMessage = "Failed to remove failure mode"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureMode.remove"))); } }; diff --git a/src/services/documentService.tsx b/src/services/documentService.tsx index eb26fee4..2044adec 100644 --- a/src/services/documentService.tsx +++ b/src/services/documentService.tsx @@ -24,8 +24,7 @@ export const importDocument = async (systemUri: string, documentId: string): Pro return new Promise((resolve) => resolve()); } catch (e) { console.log("Document Service - Failed to call /import"); - const defaultMessage = "Failed to import document"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.document.import"))); } }; @@ -38,7 +37,6 @@ export const findAll = async (): Promise => { return JsonLdUtils.compactAndResolveReferencesAsArray(response.data, CONTEXT); } catch (e) { console.log("Document Service - Failed to call /findAll"); - const defaultMessage = "Failed to load documents"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.document.findAll"))); } }; diff --git a/src/services/failureModeService.tsx b/src/services/failureModeService.tsx index 6416bcbf..aebf4e4d 100644 --- a/src/services/failureModeService.tsx +++ b/src/services/failureModeService.tsx @@ -16,8 +16,7 @@ export const findAll = async (): Promise => { return JsonLdUtils.compactAndResolveReferencesAsArray(response.data, CONTEXT); } catch (e) { console.log("Failure Mode Service - Failed to call /findAll"); - const defaultMessage = "Failed to load failure modes"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureMode.findAll"))); } }; @@ -32,8 +31,7 @@ export const find = async (failureModeIri: string): Promise => { return JsonLdUtils.compactAndResolveReferences(response.data, CONTEXT); } catch (e) { console.log("Failure Mode Service - Failed to call /find"); - const defaultMessage = "Failed to load failure mode"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureMode.find"))); } }; @@ -49,8 +47,7 @@ export const update = async (failureMode: FailureMode): Promise => return JsonLdUtils.compactAndResolveReferences(response.data, CONTEXT); } catch (e) { console.log("Failure Mode Service - Failed to call /update"); - const defaultMessage = "Failed to update failure mode"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureMode.update"))); } }; @@ -64,8 +61,7 @@ export const remove = async (failureModeIri: string): Promise => { return new Promise((resolve) => resolve()); } catch (e) { console.log("Failure Mode Service - Failed to call /remove"); - const defaultMessage = "Failed to remove failure mode"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureMode.remove"))); } }; @@ -85,8 +81,7 @@ export const addFailureModeToFunction = async (failureModeIri: string, functionI return new Promise((resolve) => resolve()); } catch (e) { console.log("Failure Mode Service - Failed to call /addFailureModeToFunction"); - const defaultMessage = "Failed to add failure mode"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureMode.add"))); } }; export const removeFailureModeToFunction = async (functionIri: string, failureModeIri: string): Promise => { @@ -101,8 +96,7 @@ export const removeFailureModeToFunction = async (functionIri: string, failureMo return new Promise((resolve) => resolve()); } catch (e) { console.log("Failure Mode Service - Failed to call /removeFailureModeToFunction"); - const defaultMessage = "Failed to remove failure mode"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureMode.remove"))); } }; @@ -125,8 +119,7 @@ export const addDependantFailureMode = async ( return new Promise((resolve) => resolve()); } catch (e) { console.log("Failure Mode Service - Failed to call /addDependantFailureMode"); - const defaultMessage = "Failed to add failure mode"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureMode.add"))); } }; export const removeDependantFailureMode = async ( @@ -145,8 +138,7 @@ export const removeDependantFailureMode = async ( return new Promise((resolve) => resolve()); } catch (e) { console.log("Failure Mode Service - Failed to call /removeDependantFailureMode"); - const defaultMessage = "Failed to remove failure mode"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureMode.remove"))); } }; @@ -162,8 +154,7 @@ export const editFailureMode = async (failureMode: FailureMode): Promise reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureMode.update"))); } }; @@ -176,7 +167,6 @@ export const getTransitiveClosure = async (failureModeUri: string, type: string) return response.data; } catch (e) { console.log("FailureMode Service - Failed to call getTransitiveClosure"); - const defaultMessage = "Failed to load component"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.component.find"))); } }; diff --git a/src/services/failureModesRowService.tsx b/src/services/failureModesRowService.tsx index ef1ea5ea..f0e0fca9 100644 --- a/src/services/failureModesRowService.tsx +++ b/src/services/failureModesRowService.tsx @@ -12,7 +12,6 @@ export const update = async (rowRpnUpdate: EditRowRpn): Promise => { return new Promise((resolve) => resolve()); } catch (e) { console.log("Failure Modes Row Service - Failed to call /update"); - const defaultMessage = "Failed to update failure modes row rpn"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureModesRow.update"))); } }; diff --git a/src/services/failureModesTableService.tsx b/src/services/failureModesTableService.tsx index 225d26d2..c14578a3 100644 --- a/src/services/failureModesTableService.tsx +++ b/src/services/failureModesTableService.tsx @@ -24,8 +24,7 @@ export const findAll = async (): Promise => { return JsonLdUtils.compactAndResolveReferencesAsArray(response.data, CONTEXT); } catch (e) { console.log("Failure Modes Table Service - Failed to call /findAll"); - const defaultMessage = "Failed to load failure modes tables"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureModesTable.findAll"))); } }; @@ -38,8 +37,7 @@ export const update = async (table: UpdateFailureModesTable): Promise(response.data, CONTEXT); } catch (e) { console.log("Failure Modes Table Service - Failed to call /update"); - const defaultMessage = "Failed to update failure modes tables"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureModesTable.update"))); } }; @@ -53,8 +51,7 @@ export const remove = async (tableIri: string): Promise => { return new Promise((resolve) => resolve()); } catch (e) { console.log("Failure Modes Table Service - Failed to call /remove"); - const defaultMessage = "Failed to remove failure modes tables"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureModesTable.remove"))); } }; @@ -68,8 +65,7 @@ export const computeTableData = async (tableIri: string): Promise resolve(response.data)); } catch (e) { console.log("Failure Modes Table Service - Failed to call /computeTableData"); - const defaultMessage = "Failed to load failure modes table data"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureModesTable.computeTableData"))); } }; @@ -89,8 +85,7 @@ export const exportCsv = async (tableIri: string, title: string): Promise reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureModesTable.export"))); } }; @@ -107,8 +102,7 @@ export const createAggregate = async (table: CreateFailureModesTable): Promise(response.data, CONTEXT); } catch (e) { console.log("Failure Modes Table Service - Failed to call /createAggregate"); - const defaultMessage = "Failed to create failure modes aggregate table"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureModesTable.createAggregate"))); } }; diff --git a/src/services/faultEventService.tsx b/src/services/faultEventService.tsx index 77a99456..f236c291 100644 --- a/src/services/faultEventService.tsx +++ b/src/services/faultEventService.tsx @@ -20,8 +20,7 @@ export const findAll = async (): Promise => { return JsonLdUtils.compactAndResolveReferencesAsArray(response.data, EVENT_CONTEXT); } catch (e) { console.log("Event Service - Failed to call /findAll"); - const defaultMessage = "Failed to find fault events"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultEvent.findAll"))); } }; @@ -35,8 +34,7 @@ export const update = async (faultEvent: FaultEvent): Promise => { return new Promise((resolve) => resolve()); } catch (e) { console.log("Event Service - Failed to call /update"); - const defaultMessage = "Failed to update fault event"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultEvent.update"))); } }; @@ -50,8 +48,7 @@ export const remove = async (faultEventIri: string): Promise => { return new Promise((resolve) => resolve()); } catch (e) { console.log("Event Service - Failed to call /remove"); - const defaultMessage = "Failed to remove fault event"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultEvent.remove"))); } }; @@ -73,8 +70,7 @@ export const addEvent = async (faultEventIri: string, event: FaultEvent): Promis return JsonLdUtils.compactAndResolveReferences(response.data, EVENT_CONTEXT); } catch (e) { console.log("Event Service - Failed to call /addEvent"); - const defaultMessage = "Failed to create event"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultEvent.create"))); } }; @@ -93,8 +89,7 @@ export const updateEventRectangle = async ( return new Promise((resolve) => resolve()); } catch (e) { console.log("Event Service - Failed to call /updateRectangle"); - const defaultMessage = "Failed to update rectangle"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultEvent.updateRectangle"))); } }; @@ -133,8 +128,7 @@ export const getFailureMode = async (eventUri: string): Promise => return JsonLdUtils.compactAndResolveReferences(response.data, FAILURE_MODE_CONTEXT); } catch (e) { console.log("Event Service - Failed to call /getFailureMode"); - const defaultMessage = "Failed to load event failure mode"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultEvent.getFailureMode"))); } }; @@ -154,8 +148,7 @@ export const addFailureMode = async (eventUri: string, failureMode: FailureMode) return JsonLdUtils.compactAndResolveReferences(response.data, FAILURE_MODE_CONTEXT); } catch (e) { console.log("Event Service - Failed to call /addFailureMode"); - const defaultMessage = "Failed to create failure mode"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureMode.create"))); } }; @@ -171,7 +164,7 @@ export const deleteFailureMode = async (eventUri: string): Promise => { } catch (e) { console.log("Event Service - Failed to call /deleteFailureMode"); const defaultMessage = "Failed to delete event failure mode"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultEvent.deleteFailureMode"))); } }; @@ -187,7 +180,7 @@ export const updateChildrenSequence = async (faultEventIri: string, childrenSequ } catch (e) { console.log("Event Service - Failed to call /updateChildrenSequence"); const defaultMessage = "Failed to update children sequence"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultEvent.updateChildrenSequence"))); } }; diff --git a/src/services/faultTreeService.tsx b/src/services/faultTreeService.tsx index 96c6c0a8..2c670501 100644 --- a/src/services/faultTreeService.tsx +++ b/src/services/faultTreeService.tsx @@ -22,8 +22,7 @@ export const findAll = async (): Promise => { return JsonLdUtils.compactAndResolveReferencesAsArray(response.data, CONTEXT); } catch (e) { console.log("Fault Tree Service - Failed to call /findAll"); - const defaultMessage = "Failed to load fault trees"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultTree.findAll"))); } }; @@ -37,8 +36,7 @@ export const find = async (faultTreeUri: string): Promise => { return JsonLdUtils.compactAndResolveReferences(response.data, CONTEXT); } catch (e) { console.log("Fault Tree Service - Failed to call /find"); - const defaultMessage = "Failed to find fault tree"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultTree.find"))); } }; @@ -53,8 +51,7 @@ export const create = async (faultTree: FaultTree): Promise => { return JsonLdUtils.compactAndResolveReferences(response.data, CONTEXT); } catch (e) { console.log("Fault Tree Service - Failed to call /create"); - const defaultMessage = "Failed to create fault tree"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultTree.create"))); } }; @@ -71,8 +68,7 @@ export const update = async (faultTree: FaultTree): Promise => { return JsonLdUtils.compactAndResolveReferences(response.data, CONTEXT); } catch (e) { console.log("Fault Tree Service - Failed to call /update"); - const defaultMessage = "Failed to update fault tree"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultTree.update"))); } }; @@ -86,8 +82,7 @@ export const remove = async (faultTreeIri: string): Promise => { return new Promise((resolve) => resolve()); } catch (e) { console.log("Fault Tree Service - Failed to call /remove"); - const defaultMessage = "Failed to remove fault tree"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultTree.remove"))); } }; @@ -101,8 +96,7 @@ export const getRootReusableEvents = async (systemIri: string): Promise(response.data, EVENT_CONTEXT); } catch (e) { console.log("Fault Tree Service - Failed to call /getRootReusableEvents"); - const defaultMessage = "Failed to find reusable fault events"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultEvent.getRootReusable"))); } }; @@ -116,8 +110,7 @@ export const getAllReusableEvents = async (faultTreeIri: string): Promise(response.data, EVENT_CONTEXT); } catch (e) { console.log("Fault Tree Service - Failed to call /getAllReusableEvents"); - const defaultMessage = "Failed to find reusable fault events"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultEvent.getRootReusable"))); } }; @@ -138,8 +131,7 @@ export const getTreePaths = async (faultTreeIri: string): Promise<[FaultEvent[]] return await parseData(response.data); } catch (e) { console.log("Fault Tree Service - Failed to call /getTreePaths"); - const defaultMessage = "Failed to load tree paths"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultTree.getTreePaths"))); } }; @@ -160,8 +152,7 @@ export const createFailureModesTable = async ( return JsonLdUtils.compactAndResolveReferences(response.data, FAILURE_MODES_TABLE_CONTEXT); } catch (e) { console.log("Fault Tree Service - Failed to call /createFailureModesTable"); - const defaultMessage = "Failed to create failure modes table"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureModesTable.create"))); } }; @@ -175,8 +166,7 @@ export const findFailureModesTable = async (faultTreeIri: string): Promise(response.data, FAILURE_MODES_TABLE_CONTEXT); } catch (e) { console.log("Fault Tree Service - Failed to call /findFailureModesTable"); - const defaultMessage = "Failed to load failure modes table"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureModesTable.findAll"))); } }; @@ -196,8 +186,7 @@ export const getTreePathsAggregate = async (): Promise<[FaultEvent[]]> => { return await parseData(response.data); } catch (e) { console.log("Fault Tree Service - Failed to call /getTreePathsAggregate"); - const defaultMessage = "Failed to load all tree paths"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultTree.getTreePathsAggregate"))); } }; @@ -212,8 +201,7 @@ export const calculateCutSets = async (faultTreeUri: string, operationalDataFilt return response; } catch (e) { console.log("Fault Tree Service - Failed to call /cutsets"); - const defaultMessage = "Failed to calculate cutsets of fault tree"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultTree.calculateCutSets"))); } }; @@ -227,7 +215,6 @@ export const findAllWithFilters = async (filters: { label?: string; snsLabel?: s return JsonLdUtils.compactAndResolveReferencesAsArray(response.data, CONTEXT); } catch (e) { console.log("Fault Tree Service - Failed to call /findAllWithFilters"); - const defaultMessage = "Failed to load fault trees with filters"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultTree.findAllWithFilters"))); } }; diff --git a/src/services/functionService.tsx b/src/services/functionService.tsx index 3aa6bf62..d3be72fd 100644 --- a/src/services/functionService.tsx +++ b/src/services/functionService.tsx @@ -21,8 +21,7 @@ export const addFailureMode = async (functionIri: string, failureModeIri: string }); } catch (e) { console.log("Function Service - Failed to call /addFailureMode"); - const defaultMessage = "Failed to add failure mode"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.failureMode.add"))); } }; @@ -34,8 +33,7 @@ export const findAllFunctions = async (): Promise => { return JsonLdUtils.compactAndResolveReferencesAsArray(response.data, FUNCTION_CONTEXT); } catch (e) { console.log("Function Service - Failed to call /functions"); - const defaultMessage = "Failed to load functions"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.function.findAll"))); } }; @@ -56,8 +54,7 @@ export const addRequiredFunction = async (functionUri: string, requiredFunctionU return JsonLdUtils.compactAndResolveReferences(response.data, FUNCTION_CONTEXT); } catch (e) { console.log("Function Service - Failed to call addRequiredFunctions"); - const defaultMessage = "Failed to add required Function"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.function.addRequiredFunction"))); } }; @@ -70,8 +67,7 @@ export const editFunction = async (f: Function): Promise => { return JsonLdUtils.compactAndResolveReferences(response.data, FUNCTION_CONTEXT); } catch (e) { console.log("Function Service - Failed to call /update"); - const defaultMessage = "Failed to update function"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.function.update"))); } }; export const getComponent = async (functionUri: string): Promise => { @@ -83,8 +79,7 @@ export const getComponent = async (functionUri: string): Promise => { return JsonLdUtils.compactAndResolveReferences(response.data, FUNCTION_CONTEXT); } catch (e) { console.log("Function Service - Failed to call /functions"); - const defaultMessage = "Failed to load component"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.component.find"))); } }; @@ -102,8 +97,7 @@ export const generateFDTree = async (functionUri: string, faultTreeName: string) return JsonLdUtils.compactAndResolveReferences(response.data, CONTEXT); } catch (e) { console.log("Fault Tree Service - Failed to call /generateRequiredFunctionsTree"); - const defaultMessage = "Failed to create fault tree"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.faultTree.create"))); } }; @@ -117,8 +111,7 @@ export const getImpairedBehavior = async (functionUri: string): Promise(response.data, FAILURE_MODE_CONTEXT); } catch (e) { console.log("Function Service - Failed to call /getImpairedBehavior"); - const defaultMessage = "Failed to get impaired behaviors"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.function.getImpairedBehaviour"))); } }; @@ -131,7 +124,6 @@ export const getTransitiveClosure = async (functionUri: string, type: string): P return response.data; } catch (e) { console.log("Function Service - Failed to call getTransitiveClosure"); - const defaultMessage = "Failed to load component"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.component.find"))); } }; diff --git a/src/services/mitigationService.tsx b/src/services/mitigationService.tsx index 4c4672ed..4230a7f2 100644 --- a/src/services/mitigationService.tsx +++ b/src/services/mitigationService.tsx @@ -14,6 +14,6 @@ export const update = async (mitigation: Mitigation): Promise => { } catch (e) { console.log("Mitigation service - Failed to call /update"); const defaultMessage = "Failed to update mitigation"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.mitigation.update"))); } }; diff --git a/src/services/systemService.tsx b/src/services/systemService.tsx index 0c06ec8e..74516c0f 100644 --- a/src/services/systemService.tsx +++ b/src/services/systemService.tsx @@ -18,8 +18,7 @@ export const findAll = async (): Promise => { return JsonLdUtils.compactAndResolveReferencesAsArray(response.data, CONTEXT); } catch (e) { console.log("System Service - Failed to call /findAll"); - const defaultMessage = "Failed to load systems"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.system.findAll"))); } }; @@ -33,8 +32,7 @@ export const find = async (systemIri: string): Promise => { return JsonLdUtils.compactAndResolveReferences(response.data, CONTEXT); } catch (e) { console.log("System Service - Failed to call /find"); - const defaultMessage = "Failed to find system"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.system.find"))); } }; @@ -49,8 +47,7 @@ export const create = async (system: System): Promise => { return JsonLdUtils.compactAndResolveReferences(response.data, CONTEXT); } catch (e) { console.log("System Service - Failed to call /create"); - const defaultMessage = "Failed to create system"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.system.create"))); } }; @@ -66,25 +63,26 @@ export const rename = async (system: System): Promise => { return JsonLdUtils.compactAndResolveReferences(response.data, CONTEXT); } catch (e) { console.log("System Service - Failed to call /update"); - const defaultMessage = "Failed to update system"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.system.update"))); } }; -export const updateFilter = async (systemUri: string, operationDataFilter: OperationalDataFilter): Promise => { +export const updateFilter = async ( + systemUri: string, + operationDataFilter: OperationalDataFilter, +): Promise => { try { const systemFragment = extractFragment(systemUri); const updateRequest = Object.assign({}, operationDataFilter, { "@context": FILTER_CONTEXT }); - await axiosClient.put(`/operational-data-filter/system/${systemFragment}`, updateRequest, { + const response = await axiosClient.put(`/operational-data-filter/system/${systemFragment}`, updateRequest, { headers: authHeaders(), }); - return new Promise((resolve) => resolve()); + return JsonLdUtils.compactAndResolveReferences(response.data, FILTER_CONTEXT); } catch (e) { console.log("System Service - Failed to call /operational-data-filter/system/${systemFragment}"); - const defaultMessage = "Failed to update minimum operational data filter"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.system.updateFilter"))); } }; @@ -98,8 +96,7 @@ export const remove = async (systemIri: string): Promise => { return new Promise((resolve) => resolve()); } catch (e) { console.log("System Service - Failed to call /remove"); - const defaultMessage = "Failed to remove system"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.system.remove"))); } }; @@ -115,8 +112,7 @@ export const addComponent = async (systemIri: string, componentUri: string): Pro return new Promise((resolve) => resolve()); } catch (e) { console.log("System Service - Failed to call /addComponent"); - const defaultMessage = "Failed to add component"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.component.add"))); } }; @@ -132,8 +128,7 @@ export const removeComponent = async (systemIri: string, componentUri: string): return new Promise((resolve) => resolve()); } catch (e) { console.log("System Service - Failed to call /removeComponent"); - const defaultMessage = "Failed to remove component"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.component.remove"))); } }; @@ -148,7 +143,6 @@ export const failureModes = async (systemIri: string): Promise => return JsonLdUtils.compactAndResolveReferencesAsArray(response.data, CONTEXT); } catch (e) { console.log("System Service - Failed to call /findAll"); - const defaultMessage = "Failed to load systems"; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.system.findAll"))); } }; diff --git a/src/services/userService.tsx b/src/services/userService.tsx index 84921535..370fbaeb 100644 --- a/src/services/userService.tsx +++ b/src/services/userService.tsx @@ -23,8 +23,7 @@ export const register = async (loginRequest: UserRegisterRequest): Promise reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.user.register"))); } }; @@ -39,8 +38,7 @@ export const login = async (loginRequest: UserLoginRequest): Promise((resolve) => resolve()); } catch (e) { console.log("Failed to call /current"); - const defaultMessage = "Password change failed."; - return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage))); + return new Promise((resolve, reject) => reject(handleServerError(e, "error.user.passwordChange"))); } }; diff --git a/src/services/utils/responseUtils.tsx b/src/services/utils/responseUtils.tsx index beee6136..e7df3dd7 100644 --- a/src/services/utils/responseUtils.tsx +++ b/src/services/utils/responseUtils.tsx @@ -1,21 +1,28 @@ import { has } from "lodash"; +import i18n from "i18next"; -export const handleServerError = (e, defaultMessage): string => { - if (has(e, "response")) { - const response = e.response; - const responseStatus = response.status; +function getResponseMessage(data: any): string { + if (has(data, "messageId")) { + return i18n.t(data.messageId); + } + + return has(data, "message") ? data.message : ""; +} + +export const handleServerError = (error: any, messageId: string): string => { + if (!has(error, "response") && !has(error.response, "data")) { + return i18n.exists(messageId) ? i18n.t(messageId, { error: "" }) : i18n.t("error.default"); + } + + const response = error.response; + const responseStatus = response.status; + const responseMessage = getResponseMessage(response.data); - switch (responseStatus) { - case 400: - if (has(response, "data") && has(response?.data, "message")) { - return response.data.message; - } - break; - default: - console.log(`Response status - ${responseStatus}`); - return defaultMessage; - } - } else { - return defaultMessage; + switch (responseStatus) { + case 400: + return i18n.exists(messageId) ? i18n.t(messageId, { error: responseMessage }) : responseMessage; + default: + console.log(`Response status - ${responseStatus}`); + return i18n.t("error.default"); } };