-
Notifications
You must be signed in to change notification settings - Fork 15
[WIP] Basic flash messaging on error #223
base: master
Are you sure you want to change the base?
Conversation
app/components/common/error/index.js
Outdated
$httpProvider.interceptors.push('errorHttpInterceptor'); | ||
}]) | ||
.run(['$window', 'error', function ($window, error) { | ||
$window.onerror = onError; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
app/components/common/error/index.js
Outdated
return { | ||
responseError: function errorHttpInterceptor (response) { | ||
//TODO maybe check response.status and redirect to 404? | ||
error(new Error(response.statusText)); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Fixes #171
Still testing this out in development.
Handles the following error scenarios
$http
window.onerror
Provides a service
error
, to display the message or via theodca.error-message
event.