"where to put toaster on http service calls typescript" Code Answer's
You're definitely familiar with the best coding language TypeScript that developers use to develop their projects and they get all their queries like "where to put toaster on http service calls typescript" answered properly. Developers are finding an appropriate answer about where to put toaster on http service calls typescript related to the TypeScript coding language. By visiting this online portal developers get answers concerning TypeScript codes question like where to put toaster on http service calls typescript. Enter your desired code related query in the search bar and get every piece of information about TypeScript code related question on where to put toaster on http service calls typescript.
where to put toaster on http service calls typescript
testApi(viewData: any): Observable<any> {
return this.http
.delete<any[]>(URL, viewData)
.pipe(
map((res: any) => {
// add snackbar or toast function here;
return res;
})
)
.pipe(
catchError((error: any) => {
// add snackbar or toast function here;
return throwError(error);
})
);
}
where to put toaster on http service calls typescript
@Injectable()
export class HttpInterceptor implements HttpInterceptor {
constructor(public toasterService: ToastrService) {}
intercept(
req: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
return next.handle(req).pipe(
tap(evt => {
if (evt instanceof HttpResponse) {
if(evt.body && evt.body.success)
this.toasterService.success(evt.body.success.message, evt.body.success.title, { positionClass: 'toast-bottom-center' });
}
}),
catchError((err: any) => {
if(err instanceof HttpErrorResponse) {
try {
this.toasterService.error(err.error.message, err.error.title, { positionClass: 'toast-bottom-center' });
} catch(e) {
this.toasterService.error('An error occurred', '', { positionClass: 'toast-bottom-center' });
}
//log error
}
return of(err);
}));
}
}
Source: stackoverflow.com
All those coders who are working on the TypeScript based application and are stuck on where to put toaster on http service calls typescript can get a collection of related answers to their query. Programmers need to enter their query on where to put toaster on http service calls typescript related to TypeScript code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about where to put toaster on http service calls typescript for the programmers working on TypeScript code while coding their module. Coders are also allowed to rectify already present answers of where to put toaster on http service calls typescript while working on the TypeScript language code. Developers can add up suggestions if they deem fit any other answer relating to "where to put toaster on http service calls typescript". Visit this developer's friendly online web community, CodeProZone, and get your queries like where to put toaster on http service calls typescript resolved professionally and stay updated to the latest TypeScript updates.