Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ErrorInterceptor {
- static $inject = ['$q'];
- constructor(private $q: ng.IQService) {}
- public request = (config) => {
- // Do something on success
- return config;
- }
- public requestError = (config) => {
- // Do something on error
- return config;
- }
- public response = (response) => {
- // Do something on success
- return response;
- }
- public responseError = (responseFailure) => {
- // Do something on error
- // Handle error codes separately if needed, e.g.:
- if (responseFailure.status === -1) {
- } else if (responseFailure.status === 401) {
- } else if (responseFailure.status === 403) {
- } else if (responseFailure.status === 404) {
- } else if (responseFailure.status === 500) {
- } else if (responseFailure.status === 503) {
- } else {
- }
- return this.$q.reject(responseFailure);
- }
- }
- const ErrorInterceptorConfig = ['$httpProvider', ($httpProvider) => {
- $httpProvider.interceptors.push('ErrorInterceptor');
- }];
- // Register the service and configuration:
- angular.module('yourModule')
- .service('ErrorInterceptor', ErrorInterceptor)
- .config(ErrorInterceptorConfig);
Add Comment
Please, Sign In to add comment