Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
feat(core): Add error handler for failed requests (#1557)
Browse files Browse the repository at this point in the history
Add error handle for failed requests(no response from server)
Using Notification.error to show error message
Added test for the notification in Auth Interceptor

Fixes #1556
  • Loading branch information
sujeethk authored and mleanos committed Oct 12, 2016
1 parent baa291a commit d5b8ffa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
case 404:
$injector.get('$state').go('not-found', { message: rejection.data.message });
break;
case -1: // Handle error if no response from server(Network Lost or Server not responding)
var Notification = $injector.get('Notification');
Notification.error({ message: 'No response received from server. Please try again later.', title: 'Error processing request!', delay: 5000 });
break;
}
}
// otherwise, default behaviour
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,22 @@
expect($state.transitionTo).toHaveBeenCalledWith('authentication.signin');
});
});

describe('Unresponsive Interceptor', function() {
var Notification;
beforeEach(inject(function(_Notification_) {
Notification = _Notification_;
spyOn(Notification, 'error');
}));
it('should show error Notification', function () {
var response = {
status: -1,
config: {}
};
var promise = authInterceptor.responseError(response);
expect($q.reject).toHaveBeenCalled();
expect(Notification.error).toHaveBeenCalledWith({ message: 'No response received from server. Please try again later.', title: 'Error processing request!', delay: 5000 });
});
});
});
}());

0 comments on commit d5b8ffa

Please sign in to comment.