Answers for "http error response angular"

0

angular http error handling

// src/app/services/interceptor.service.ts
    import { Injectable } from '@angular/core';
    import {
    HttpInterceptor, HttpRequest,
    HttpHandler, HttpEvent, HttpErrorResponse
    } from '@angular/common/http';
    import { Observable, throwError } from 'rxjs';
    import { catchError } from 'rxjs/operators';
    @Injectable({
    providedIn: 'root'
    })
    export class InterceptorService implements HttpInterceptor{
     constructor() { }
     handleError(error: HttpErrorResponse){
      console.log("lalalalalalalala");
      return throwError(error);
     }
    intercept(req: HttpRequest<any>, next: HttpHandler):
    Observable<HttpEvent<any>>{
     return next.handle(req)
     .pipe(
      catchError(this.handleError)
     )
     };
    }
Posted by: Guest on November-29-2020
0

http error response angular

class HttpErrorResponse extends HttpResponseBase implements Error {
  constructor(init: { error?: any; headers?: HttpHeaders; status?: number; statusText?: string; url?: string; })
  name: 'HttpErrorResponse'
  message: string
  error: any | null
  override
  ok: false

  // inherited from common/http/HttpResponseBase
  constructor(init: { headers?: HttpHeaders; status?: number; statusText?: string; url?: string; }, defaultStatus: number = HttpStatusCode.Ok, defaultStatusText: string = 'OK')
  headers: HttpHeaders
  status: number
  statusText: string
  url: string | null
  ok: boolean
  type: HttpEventType.Response | HttpEventType.ResponseHeader
}
Posted by: Guest on September-17-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language