Skip to content
Snippets Groups Projects
Verified Commit c3ad7733 authored by Alex ORLUC's avatar Alex ORLUC
Browse files

clean and fix handleErrors

parent ed7e4f7d
No related branches found
No related tags found
No related merge requests found
import {MatSnackBar} from '@angular/material';
import {Injectable,Component,Inject} from '@angular/core';
import {MAT_SNACK_BAR_DATA} from '@angular/material';
import { MatSnackBar } from '@angular/material';
import { Injectable, Component, Inject } from '@angular/core';
import { MAT_SNACK_BAR_DATA } from '@angular/material';
import { Router } from '@angular/router';
import { LANG } from './translate.component';
@Component({
selector: 'custom-snackbar',
template: '<mat-grid-list cols="4" rowHeight="1:1"><mat-grid-tile colspan="1"><mat-icon class="fa fa-{{data.icon}} fa-2x"></mat-icon></mat-grid-tile><mat-grid-tile colspan="3">{{data.message}}</mat-grid-tile></mat-grid-list>' // You may also use a HTML file
......@@ -13,34 +13,36 @@ export class CustomSnackbarComponent {
@Injectable()
export class NotificationService {
lang: any = LANG;
constructor(private router: Router, public snackBar: MatSnackBar) {
}
success(message:string) {
this.snackBar.openFromComponent(CustomSnackbarComponent,{
success(message: string) {
this.snackBar.openFromComponent(CustomSnackbarComponent, {
duration: 2000,
data: {message: message,icon : 'info-circle'}
});
data: { message: message, icon: 'info-circle' }
});
}
error(message:string) {
this.snackBar.openFromComponent(CustomSnackbarComponent,{
error(message: string) {
this.snackBar.openFromComponent(CustomSnackbarComponent, {
duration: 2000,
data: {message: message,icon : 'exclamation-triangle'}
});
data: { message: message, icon: 'exclamation-triangle' }
});
}
handleErrors(err: any) {
console.log(err);
if (err.status === 401 && this.router.url !== '/login') {
this.router.navigate(['/login']);
this.error('Veuillez vous reconnecter');
if (err.status === 401 && this.router.url !== '/home') {
this.router.navigate(['/home']);
this.error(this.lang.mustReconnect);
} else if (err.status === 0 && err.statusText === 'Unknown Error') {
this.error('La connexion au serveur a échoué. Veuillez réessayer ultérieurement.');
this.error(this.lang.connectionFailed);
} else {
if (err.error.errors !== undefined) {
this.error(err.error.errors);
if (err.status === 403 || err.status === 404) {
this.router.navigate(['/documents']);
this.router.navigate(['/home']);
}
} else if (err.error.exception !== undefined) {
this.error(err.error.exception[0].message);
......
......@@ -723,4 +723,6 @@ export const LANG_EN = {
"internalParam" : "Internal configuration",
"enableAuth" : "Activate authentication",
"checkSendmail" : "Check mail server status",
"mustReconnect" : "Please reconnect",
"connectionFailed" : "Connection to server failed, please try later.",
};
......@@ -749,6 +749,8 @@ export const LANG_FR = {
"smtpRelayDesc" : "Utilisation d'un relai smtp du serveur (ssmtp par exemple), configuration externe à l'application",
"internalParam" : "Configuration interne",
"internalParamDesc" : "Utilisateur du module interne phpmailer de l'application",
"enableAuth" : "Activer l'authentification",
"enableAuth" : "Activer l'authentification",
"checkSendmail" : "Vérifier l'état du serveur",
"mustReconnect" : "Veuillez vous reconnecter",
"connectionFailed" : "La connexion au serveur a échoué. Veuillez réessayer ultérieurement.",
};
......@@ -752,4 +752,6 @@ export const LANG_NL = {
"internalParam" : "_TO_TRANSLATE",
"enableAuth" : "_TO_TRANSLATE",
"checkSendmail" : "_TO_TRANSLATE",
"mustReconnect" : "_TO_TRANSLATE",
"connectionFailed" : "_TO_TRANSLATE",
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment