question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Overwrite error method?

See original GitHub issue

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:

// 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:closed
  • Created 8 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
alexlafrosciacommented, Feb 19, 2016

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 handleResponse hook, check the return type of the original handler, detect the type of error using the provided checking functions (details on isUnauthorizedError 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.

0reactions
alexlafrosciacommented, Jun 17, 2016

@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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found