Overwrite error method?
See original GitHub issueI 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:
// app/services/ajax.js
import AjaxService from 'ember-ajax/services/ajax';
export default AjaxService.extend({
isUnauthorized(status, headers, payload ) {
// some custom logic
}
});
Rather than handling specific errors on each request, is it possible to handle them globally?
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Override method error - java
So your compiler thinks that there is an abstract method push() out there which you never overrode (even though you did, at least...
Read more >Method Overriding Error in C# - MSDN - Microsoft
It's not possible to override any method without specifying (1) the same method name, (2) the same parameter type(s) and the same returned...
Read more >Error while creating a overwrite method in class
Hello. I'm trying to create an overwrite method in the class CL_HREIC_EECONTACT2SRCHV_IMPL but it just won't let me. Every time I try I...
Read more >Overriding and Hiding Methods (The Java™ Tutorials ...
The ability of a subclass to override a method allows a class to inherit from a superclass whose behavior is "close enough" and...
Read more >What is @Override? Fix method does not override ... - YouTube
What is the @ Override annotation? What methods do I put it on? How do I fix " method does not override or...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Right now, the way to do that would probably be overwriting the
So instead of providing specific hooks (which could become kind of messy, given a bunch of possible errors) you can use the single
handleResponse
hook, check the return type of the original handler, detect the type of error using the provided checking functions (details onisUnauthorizedError
can be found here) and then do your custom handling however you want to.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
isUnauthorizedError
method on the service, which is defined here and used here.@urbany Thanks! @taras and I are planning to put together a little documentation site with examples and stuff of these kinds of things, since I want to avoid saturating the README with too much information. I’ll make sure that that example ends up in there!