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.

Interceptors and unhandled promise rejection

See original GitHub issue

Summary

I am using a interceptor to handle errors globally but I am still getting “Unhandled promise rejection” errors on the console for every request.

axios.interceptors.response.use(
  response => response,
  error => {
    console.log(error.message);
    return Promise.reject(error);
}
----
axios.get('some-url').then(response => /* handle response */);
----
> Error Message
> Unhandled promise rejection Error: "Error message"

Context

  • axios version: 0.18.0
  • Environment: Firefox 64, Linux

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10

github_iconTop GitHub Comments

8reactions
svpacecommented, Jan 3, 2019

This is exactly what I was trying to avoid. All error handling should be taken care of in the interceptor. I would like to avoid the boilerplate of adding an empty catch in every request.

4reactions
agronickcommented, May 22, 2019

@guilhermehn Then every request has a result that doesn’t match the result it was expecting. I think a lot of people, myself included would like to do something like log the user out on a 401 response and not have it resolve or reject.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to handle unhandledrejection errors using axios
Axios is a great library, but unhandled promise rejections can be a problem. ... If you look at the interceptor, we are handling...
Read more >
Handling a Promise reject in axios interceptor - Stack Overflow
Having trouble dealing with a specific case of an error, seems like my understanding of promises is flawed. Central error handling in axios ......
Read more >
Preventing unhandled promise rejections in async functions
How to prevent unhandled promise rejections when using async/ await. ... unhandledRejection RequestError: HTTP request error. at ...
Read more >
keywords:unhandledRejection - npm search
Track the list of currently unhandled promise rejections. unhandled · unhandledRejection · rejected · promises · jamestalmage. published 0.4.1 • 6 years ago ......
Read more >
Processing Request | Alexa Skills Kit - Amazon Developer
Request handlers, request and response interceptors, and error handlers are all ... accepts HandlerInput and returns a Response or Promise<Response> .
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