Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F60605064
error.interceptor.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, May 1, 10:22
Size
873 B
Mime Type
text/x-java
Expires
Fri, May 3, 10:22 (2 d)
Engine
blob
Format
Raw Data
Handle
17382421
Attached To
rDDJUDGECLIENT JudgeMyRace Client
error.interceptor.ts
View Options
import { Injectable } from '@angular/core';
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { AuthenticationService } from '../_services';
// Error interceptor
@Injectable()
export class ErrorInterceptor implements HttpInterceptor {
constructor(private authenticationService: AuthenticationService) {}
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request).pipe(catchError(err => {
if (err.status === 401) {
// auto logout if 401 response returned from api
this.authenticationService.logout();
location.reload(true);
}
const error = err.error.message || err.statusText;
return throwError(error);
}));
}
}
Event Timeline
Log In to Comment