Improved error display

This commit is contained in:
Arnaud Vergnet 2020-06-26 12:03:08 +02:00
parent 6ac459e58a
commit 72c5a91f75
6 changed files with 20 additions and 3 deletions

View file

@ -28,6 +28,12 @@ class ErrorDialog extends React.PureComponent<Props> {
case ERROR_TYPE.NO_CONSENT: case ERROR_TYPE.NO_CONSENT:
this.message = i18n.t("errors.noConsent"); this.message = i18n.t("errors.noConsent");
break; 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: case ERROR_TYPE.BAD_INPUT:
this.message = i18n.t("errors.badInput"); this.message = i18n.t("errors.badInput");
break; break;
@ -44,6 +50,7 @@ class ErrorDialog extends React.PureComponent<Props> {
this.message = i18n.t("errors.unknown"); this.message = i18n.t("errors.unknown");
break; break;
} }
this.message += "\n\nCode " + this.props.errorCode;
} }
render() { render() {

View file

@ -45,6 +45,7 @@ class ErrorView extends React.PureComponent<Props, State> {
constructor(props) { constructor(props) {
super(props); super(props);
this.colors = props.theme.colors; this.colors = props.theme.colors;
this.icon = "";
} }
generateMessage() { generateMessage() {
@ -64,6 +65,10 @@ class ErrorView extends React.PureComponent<Props, State> {
this.message = i18n.t("errors.noConsent"); this.message = i18n.t("errors.noConsent");
this.icon = "account-remove-outline"; this.icon = "account-remove-outline";
break; break;
case ERROR_TYPE.TOKEN_SAVE:
this.message = i18n.t("errors.tokenSave");
this.icon = "alert-circle-outline";
break;
case ERROR_TYPE.BAD_INPUT: case ERROR_TYPE.BAD_INPUT:
this.message = i18n.t("errors.badInput"); this.message = i18n.t("errors.badInput");
this.icon = "alert-circle-outline"; this.icon = "alert-circle-outline";
@ -85,6 +90,7 @@ class ErrorView extends React.PureComponent<Props, State> {
this.icon = "alert-circle-outline"; this.icon = "alert-circle-outline";
break; break;
} }
this.message += "\n\nCode " + this.props.errorCode;
} else { } else {
this.message = this.props.message; this.message = this.props.message;
this.icon = this.props.icon; this.icon = this.props.icon;

View file

@ -122,7 +122,7 @@ export default class ConnectionManager {
resolve(true); resolve(true);
}) })
.catch(() => { .catch(() => {
reject(ERROR_TYPE.UNKNOWN); reject(ERROR_TYPE.TOKEN_SAVE);
}); });
}) })
.catch((error) => reject(error)); .catch((error) => reject(error));
@ -151,7 +151,7 @@ export default class ConnectionManager {
.then((response) => resolve(response)) .then((response) => resolve(response))
.catch((error) => reject(error)); .catch((error) => reject(error));
} else } else
reject(ERROR_TYPE.UNKNOWN); reject(ERROR_TYPE.TOKEN_RETRIEVE);
}); });
} }
} }

View file

@ -5,6 +5,8 @@ export const ERROR_TYPE = {
BAD_CREDENTIALS: 1, BAD_CREDENTIALS: 1,
BAD_TOKEN: 2, BAD_TOKEN: 2,
NO_CONSENT: 3, NO_CONSENT: 3,
TOKEN_SAVE: 4,
TOKEN_RETRIEVE: 5,
BAD_INPUT: 400, BAD_INPUT: 400,
FORBIDDEN: 403, FORBIDDEN: 403,
CONNECTION_ERROR: 404, CONNECTION_ERROR: 404,
@ -41,7 +43,7 @@ export async function apiRequest(path: string, method: string, params: ?Object)
else else
reject(response.error); reject(response.error);
} else } else
reject(ERROR_TYPE.CONNECTION_ERROR); reject(ERROR_TYPE.SERVER_ERROR);
}) })
.catch(() => { .catch(() => {
reject(ERROR_TYPE.CONNECTION_ERROR); reject(ERROR_TYPE.CONNECTION_ERROR);

View file

@ -259,6 +259,7 @@
"badCredentials": "Email or password invalid.", "badCredentials": "Email or password invalid.",
"badToken": "You are not logged in. Please login and try again.", "badToken": "You are not logged in. Please login and try again.",
"noConsent": "You did not give your consent for data processing to the Amicale.", "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.", "badInput": "Invalid input. Please try again.",
"forbidden": "You do not have access to this data.", "forbidden": "You do not have access to this data.",
"connectionError": "Network error. Please check your internet connection.", "connectionError": "Network error. Please check your internet connection.",

View file

@ -259,6 +259,7 @@
"badCredentials": "Email ou mot de passe invalide.", "badCredentials": "Email ou mot de passe invalide.",
"badToken": "Vous n'êtes pas connecté. Merci de vous connecter puis réessayez.", "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.", "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.", "badInput": "Entrée invalide. Merci de réessayer.",
"forbidden": "Vous n'avez pas accès à cette information.", "forbidden": "Vous n'avez pas accès à cette information.",
"connectionError": "Erreur de réseau. Merci de vérifier votre connexion Internet.", "connectionError": "Erreur de réseau. Merci de vérifier votre connexion Internet.",