I have a situation where I call an API to save data both manually and automatically,
- In the case of manual save I want to show the error if the save fails, and I achieved this using an angular global error handler.
- In the case of automatic save I want to ignore the error, but as I have a global error handler it's catching the error and showing it to the user as per the implementation.
I am trying to find a way to manage this error handling based on some conditions.
following are some code snippets for a better understating of the problem
Global error handler
export class GlobalErrorHandlerService implements ErrorHandler {
constructor(private notification2Service: NotificationService,
private loggingService: LoggingApiService) {
}
handleError(error: any): void {
this.notification2Service.notify(error.message);
this.loggingService.logError(error);
}
}
Save method
post(path: string, body: Object = {}, skipSpinner = 'false'): Observable<any> {
let fullPath = this.getBaseApiUrl(path);
return this.http.post(fullPath,body,{
headers: {'skip-spinner':skipSpinner}
});
}
what I want is global error handler should ignore errors in this call if "skipSpinner" is 'true'