From 72c5a91f75893ff17ff12e66ea207095ae9a51ea Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Fri, 26 Jun 2020 12:03:08 +0200 Subject: [PATCH] Improved error display --- src/components/Dialogs/ErrorDialog.js | 7 +++++++ src/components/Screens/ErrorView.js | 6 ++++++ src/managers/ConnectionManager.js | 4 ++-- src/utils/WebData.js | 4 +++- translations/en.json | 1 + translations/fr.json | 1 + 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/components/Dialogs/ErrorDialog.js b/src/components/Dialogs/ErrorDialog.js index f357a5f..68d4f3f 100644 --- a/src/components/Dialogs/ErrorDialog.js +++ b/src/components/Dialogs/ErrorDialog.js @@ -28,6 +28,12 @@ class ErrorDialog extends React.PureComponent { case ERROR_TYPE.NO_CONSENT: this.message = i18n.t("errors.noConsent"); break; + case ERROR_TYPE.TOKEN_SAVE: + this.message = i18n.t("errors.tokenSave"); + break; + case ERROR_TYPE.TOKEN_RETRIEVE: + this.message = i18n.t("errors.unknown"); + break; case ERROR_TYPE.BAD_INPUT: this.message = i18n.t("errors.badInput"); break; @@ -44,6 +50,7 @@ class ErrorDialog extends React.PureComponent { this.message = i18n.t("errors.unknown"); break; } + this.message += "\n\nCode " + this.props.errorCode; } render() { diff --git a/src/components/Screens/ErrorView.js b/src/components/Screens/ErrorView.js index 19d4704..b33d552 100644 --- a/src/components/Screens/ErrorView.js +++ b/src/components/Screens/ErrorView.js @@ -45,6 +45,7 @@ class ErrorView extends React.PureComponent { constructor(props) { super(props); this.colors = props.theme.colors; + this.icon = ""; } generateMessage() { @@ -64,6 +65,10 @@ class ErrorView extends React.PureComponent { this.message = i18n.t("errors.noConsent"); this.icon = "account-remove-outline"; break; + case ERROR_TYPE.TOKEN_SAVE: + this.message = i18n.t("errors.tokenSave"); + this.icon = "alert-circle-outline"; + break; case ERROR_TYPE.BAD_INPUT: this.message = i18n.t("errors.badInput"); this.icon = "alert-circle-outline"; @@ -85,6 +90,7 @@ class ErrorView extends React.PureComponent { this.icon = "alert-circle-outline"; break; } + this.message += "\n\nCode " + this.props.errorCode; } else { this.message = this.props.message; this.icon = this.props.icon; diff --git a/src/managers/ConnectionManager.js b/src/managers/ConnectionManager.js index 0151f45..098a435 100644 --- a/src/managers/ConnectionManager.js +++ b/src/managers/ConnectionManager.js @@ -122,7 +122,7 @@ export default class ConnectionManager { resolve(true); }) .catch(() => { - reject(ERROR_TYPE.UNKNOWN); + reject(ERROR_TYPE.TOKEN_SAVE); }); }) .catch((error) => reject(error)); @@ -151,7 +151,7 @@ export default class ConnectionManager { .then((response) => resolve(response)) .catch((error) => reject(error)); } else - reject(ERROR_TYPE.UNKNOWN); + reject(ERROR_TYPE.TOKEN_RETRIEVE); }); } } diff --git a/src/utils/WebData.js b/src/utils/WebData.js index 3f354e3..3fecfe3 100644 --- a/src/utils/WebData.js +++ b/src/utils/WebData.js @@ -5,6 +5,8 @@ export const ERROR_TYPE = { BAD_CREDENTIALS: 1, BAD_TOKEN: 2, NO_CONSENT: 3, + TOKEN_SAVE: 4, + TOKEN_RETRIEVE: 5, BAD_INPUT: 400, FORBIDDEN: 403, CONNECTION_ERROR: 404, @@ -41,7 +43,7 @@ export async function apiRequest(path: string, method: string, params: ?Object) else reject(response.error); } else - reject(ERROR_TYPE.CONNECTION_ERROR); + reject(ERROR_TYPE.SERVER_ERROR); }) .catch(() => { reject(ERROR_TYPE.CONNECTION_ERROR); diff --git a/translations/en.json b/translations/en.json index 3ef4104..c749d02 100644 --- a/translations/en.json +++ b/translations/en.json @@ -259,6 +259,7 @@ "badCredentials": "Email or password invalid.", "badToken": "You are not logged in. Please login and try again.", "noConsent": "You did not give your consent for data processing to the Amicale.", + "tokenSave": "Could not save session token. Please contact support.", "badInput": "Invalid input. Please try again.", "forbidden": "You do not have access to this data.", "connectionError": "Network error. Please check your internet connection.", diff --git a/translations/fr.json b/translations/fr.json index 76c6a33..d3538ca 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -259,6 +259,7 @@ "badCredentials": "Email ou mot de passe invalide.", "badToken": "Vous n'êtes pas connecté. Merci de vous connecter puis réessayez.", "noConsent": "Vous n'avez pas donné votre consentement pour l'utilisation de vos données personnelles.", + "tokenSave": "Impossible de sauvegarder le token de session. Merci de contacter le support.", "badInput": "Entrée invalide. Merci de réessayer.", "forbidden": "Vous n'avez pas accès à cette information.", "connectionError": "Erreur de réseau. Merci de vérifier votre connexion Internet.",