Both then and catch executing in same call
See original GitHub issueI’m doing this call:
axios.get('/groups', {
baseURL: 'http://localhost:5000',
headers: { Authorization: 'Bearer ' + getAccessToken(), 'Content-Type': 'application/json; charset=utf-8' }
})
.then((response) => {
console.log('then response',response)
success(response.data)} )
.catch((response) => {
console.log('catch response',response)
error(response.status, response.data.description)})
I’m calling this exactly once. I get a 200 OK response, then
block executes, with response
being an object I would normally expect. Right after that catch
executes, response being a string:
TypeError: Cannot read property 'groups' of null(…)
Closing: my bad, it was an error somewhere very far in the code, still trying to figure out how it made it into the promise…
Issue Analytics
- State:
- Created 8 years ago
- Reactions:8
- Comments:15
Top Results From Across the Web
Why do both Promise's then & catch callbacks get called?
The then callback gets called because the catch callback is before it, not after. The rejection has already been handled by catch ....
Read more >Using .then(), .catch(), .finally() to Handle Errors in Javascript ...
A Promise executes immediately and either resolves to a single value, or rejects with an error object. If the promise is rejected, the...
Read more >JavaScript Promises – The promise.then, promise.catch and ...
A promise is an object in JavaScript that will produce a value sometime in the future. This usually applies to asynchronous operations.
Read more >Promise.prototype.catch() - JavaScript - MDN Web Docs
The catch() method of a Promise object schedules a function to be called when the promise is rejected. It immediately returns an equivalent ......
Read more >Error handling, "try...catch" - The Modern JavaScript Tutorial
If an error occurs, then the try execution is stopped, ... Now catch became a single place for all error handling: both for...
Read more >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 FreeTop 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
Top GitHub Comments
This just happens to me and my problem was (correct me if I’m wrong) that any kind of error you have inside the
then()
callback it will be caught by the “catch” callback.Example:
I have the same error. Both then and catch executing in same call