1 // src/app/services/interceptor.service.ts
2 import { Injectable } from '@angular/core';
3 import {
4 HttpInterceptor, HttpRequest,
5 HttpHandler, HttpEvent, HttpErrorResponse
6 } from '@angular/common/http';
7 import { Observable, throwError } from 'rxjs';
8 import { catchError } from 'rxjs/operators';
9 @Injectable({
10 providedIn: 'root'
11 })
12 export class InterceptorService implements HttpInterceptor{
13 constructor() { }
14 handleError(error: HttpErrorResponse){
15 console.log("lalalalalalalala");
16 return throwError(error);
17 }
18 intercept(req: HttpRequest<any>, next: HttpHandler):
19 Observable<HttpEvent<any>>{
20 return next.handle(req)
21 .pipe(
22 catchError(this.handleError)
23 )
24 };
25 }
1
2 class HttpErrorResponse extends HttpResponseBase implements Error {
3 constructor(init: { error?: any; headers?: HttpHeaders; status?: number; statusText?: string; url?: string; })
4 name: 'HttpErrorResponse'
5 message: string
6 error: any | null
7 override
8 ok: false
9
10 // inherited from common/http/HttpResponseBase
11 constructor(init: { headers?: HttpHeaders; status?: number; statusText?: string; url?: string; }, defaultStatus: number = HttpStatusCode.Ok, defaultStatusText: string = 'OK')
12 headers: HttpHeaders
13 status: number
14 statusText: string
15 url: string | null
16 ok: boolean
17 type: HttpEventType.Response | HttpEventType.ResponseHeader
18}
19