Dear Sir/Madam,
I have implemented the error interceptor. It works fine.
Now, I have a situation where I call the same node.js service in 2 places in my application - while I add a new record and when I upload bulk data.
When I add record, if HTTP error is detected, it should display the display. But when I am uploading data, the dialog should not be display. I will handle the error separately.
Is it possible?
Regards,
Partha
Hi Partha,
Yes, that is possible. The easiest way is adding (and inspect) a flag to your request. I would add a custom header to my requests, that way I can inspect it server side too.
http.post(someUrl,someData,{header:{"se-error-handling":"none"}})
inspect that in your error interceptor, and don’t handle the error when the header is present.
Regards
Sander
| intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request)
.catch(response => {
if (!response instanceof HttpErrorResponse) {
// network error, ignore or whatevs
return throwError(response);
}
// we got an error from backend. Options:
// you can check e.g. request method
if (response instanceof HttpErrorResponse && request.method === 'PUT') {
// show or not show the dialog
..
// alternatively check by your calling URL
} else if (request.url.contains('bulk-upload-endpoint') {
// special handling here
}
Or if it is just one endpoint that needs special handling, catch error there on the call site and swallow it.
Hope that gives you ideas.
| |
--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.