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.

Both then and catch executing in same call

See original GitHub issue

I’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:closed
  • Created 8 years ago
  • Reactions:8
  • Comments:15

github_iconTop GitHub Comments

104reactions
dacastro4commented, Jan 26, 2018

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:

axios.get(url)
    .then( data => {
        //some sort of error
    })
    .catch(error => {
        /it's gonna fall here. If you console log "error" is gonna be the error that happened in the then callback 
    })
12reactions
nilaybrahmbhattcommented, Dec 31, 2016

I have the same error. Both then and catch executing in same call

Read more comments on GitHub >

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

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