-
-
Notifications
You must be signed in to change notification settings - Fork 87
Overwrite error method? #57
Comments
Do you mean for detecting the errors? Or specifying a handler function on a per-error-type ( |
Right now, the way to do that would probably be overwriting the import AjaxService from 'ember-ajax/services/ajax';
import { isUnauthorizedError } from 'ember-ajax/errors';
export default AjaxService.extend({
handleResponse() {
const result = this._super(...arguments);
if (isUnauthorizedError(result)) {
// Do whatever you need to do
} else {
return result;
}
}
}); So instead of providing specific hooks (which could become kind of messy, given a bunch of possible errors) you can use the single Alternatively, if you want to change how an "unauthorized error" is detected (and maybe try some other logic before deciding to throw an error) you can overwrite the |
The former is exactly what I was looking for, just didn't realize I had to import the error. (Still getting the hang of es6.) Thanks @alexlafroscia |
No problem! You could also do a simple type check of the if (result instanceof UnauthorizedError) {
// ...
} But then you need to import |
I think we should make helpers the recommended way to tests errors because Taras Mankovski |
Yeah, for sure. I was more just pointing out that the |
Hi @alexlafroscia this handleResponse method is very interesting, it would be great if you could add it to the README, this exact example is very helpful. |
I see an example for "globally" handling errors when the status is 200, but what about other status codes like 401 or 403?
I would think something like this would be possible:
Rather than handling specific errors on each request, is it possible to handle them globally?
The text was updated successfully, but these errors were encountered: