Created
August 25, 2020 09:16
-
-
Save rgabaydullov/81cdd60408c0d984a16ded9f3c9d0ccb to your computer and use it in GitHub Desktop.
Angular error handling example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NgModule, Errorhandler } from '@angular/core'; | |
@Injectable | |
export class CustomErrorHandler extends ErrorHandler { | |
handleError(error) { | |
return middlewareErrorHandler(error); | |
} | |
} | |
// ... | |
@NgModule({ | |
providers: [ | |
{ | |
provide: ErrorHandler, | |
/* здесь зависит от вашей фантазии, воспользоваться классом или методом */ | |
useValue: customErrorHandler(), | |
useClass: CustomErrorHandler, | |
}, | |
// дополнительно можно встроить обработчики для разных провайдеров по типу HttpService | |
], | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment