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

FEAT #8956 add handle errors for list v2

parent 5581eb18
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ import { MatDialog, MatSidenav, MatPaginator, MatSort, MatBottomSheet, MatBottom
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { startWith, switchMap, map, catchError } from 'rxjs/operators';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { HeaderService } from '../../service/header.service';
import { FiltersListService } from '../../service/filtersList.service';
import { NotesListComponent } from '../notes/notes.component';
......@@ -107,7 +107,7 @@ export class BasketListComponent implements OnInit {
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild('tableBasketListSort') sort: MatSort;
constructor(changeDetectorRef: ChangeDetectorRef, private route: ActivatedRoute, media: MediaMatcher, public http: HttpClient, public dialog: MatDialog, private sanitizer: DomSanitizer, private bottomSheet: MatBottomSheet, private headerService: HeaderService, public filtersListService: FiltersListService) {
constructor(changeDetectorRef: ChangeDetectorRef, private router: Router, private route: ActivatedRoute, media: MediaMatcher, public http: HttpClient, public dialog: MatDialog, private sanitizer: DomSanitizer, private bottomSheet: MatBottomSheet, private headerService: HeaderService, public filtersListService: FiltersListService, private notify: NotificationService) {
this.mobileMode = angularGlobals.mobileMode;
$j("link[href='merged_css.php']").remove();
this.mobileQuery = media.matchMedia('(max-width: 768px)');
......@@ -151,6 +151,9 @@ export class BasketListComponent implements OnInit {
this.refreshDao();
},
(err : any) => {
this.notify.handleErrors(err);
});
}
......@@ -177,7 +180,8 @@ export class BasketListComponent implements OnInit {
return data.resources;
}),
catchError((err: any) => {
console.log(err);
this.notify.handleErrors(err);
this.router.navigate(['/home']);
this.isLoadingResults = false;
return observableOf([]);
})
......
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';
@Component({
selector: 'custom-snackbar',
......@@ -12,7 +13,7 @@ export class CustomSnackbarComponent {
@Injectable()
export class NotificationService {
constructor(public snackBar: MatSnackBar) {
constructor(private router: Router, public snackBar: MatSnackBar) {
}
success(message:string) {
this.snackBar.openFromComponent(CustomSnackbarComponent,{
......@@ -27,4 +28,25 @@ export class NotificationService {
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');
} else if (err.status === 0 && err.statusText === 'Unknown Error') {
this.error('La connexion au serveur a échoué. Veuillez réessayer ultérieurement.');
} else {
if (err.error.errors !== undefined) {
this.error(err.error.errors);
if (err.status === 403 || err.status === 404) {
this.router.navigate(['/documents']);
}
} else if (err.error.exception !== undefined) {
this.error(err.error.exception[0].message);
} else {
this.error(err.error.error.message);
}
}
}
}
\ No newline at end of file
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