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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With