Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Http interceptor Error Response in complete in chrome

I am facing weird issue while working with httpinterceptor in angular 5. I am not able to get the error response and error status code in Chrome and but able to get in IE below is my HttpInterceptor code.

import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpResponse } 
from '@angular/common/http';
import { finalize, tap } from 'rxjs/operators';

@Injectable()
export class LoggingInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler) {
const startTime = Date.now();
let status: string;

return next.handle(req).pipe(
    tap(
      event => {
        status = '';
        if (event instanceof HttpResponse) {
          status = 'succeeded';
        }
      },
      error => {
        if(error instanceof HttpErrorResponse)  {
          console.log(error.error.message) 
          // Above message is printing in IE but no in chorme.
       }
     }
    ),
    finalize(() => {

    })
);
 }

} 

In the above Error block the message and status code I am able to see in IE but not in Chrome. Kindly help me how to resolve this.

Edit: I am consuming data from different origin and cors is enabled in web services

like image 517
Surya Prakash Tumma Avatar asked Aug 16 '18 18:08

Surya Prakash Tumma


1 Answers

I found the issue, It is due to not setting response headers on errors at server side. Server is throwing exception directly for errors without setting response headers. I have set response headers at server side and now I am able to see the error message in chrome.

Still I am confused how come IE able to respond on this errors.

like image 75
Surya Prakash Tumma Avatar answered Oct 14 '22 19:10

Surya Prakash Tumma