Skip to content
This repository was archived by the owner on Aug 8, 2018. It is now read-only.

[WIP] Basic flash messaging on error#223

Open
adborden wants to merge 2 commits intomasterfrom
feature/error-flash
Open

[WIP] Basic flash messaging on error#223
adborden wants to merge 2 commits intomasterfrom
feature/error-flash

Conversation

@adborden
Copy link
Member

@adborden adborden commented Oct 8, 2016

Fixes #171

Still testing this out in development.

Handles the following error scenarios

  • XHR errors via $http
  • Global exception handler
  • window.onerror

Provides a service error, to display the message or via the odca.error-message event.

screenshot from 2016-10-07 23-36-55

$httpProvider.interceptors.push('errorHttpInterceptor');
}])
.run(['$window', 'error', function ($window, error) {
$window.onerror = onError;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to avoid the global here. And if we can't, we should give it an odca prefix just in case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean, the onerror? I'm just hooking into the browser's global error handler.

return {
responseError: function errorHttpInterceptor (response) {
//TODO maybe check response.status and redirect to 404?
error(new Error(response.statusText));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be sure to rethrow the error or return a rejected promise here. Otherwise, errors get treated as successes in subsequent functions in the promise chain. It's effectively a catch. https://docs.angularjs.org/api/ng/service/$http

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point. In that case, I'm thinking we don't need any handler here at all, that way the default http handler will just throw the error and the global handler will catch it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants