Skip to content
This repository has been archived by the owner on Dec 20, 2020. It is now read-only.

undefined xhr and response objects on last catch #113

Closed
sheymann opened this issue Feb 25, 2016 · 13 comments
Closed

undefined xhr and response objects on last catch #113

sheymann opened this issue Feb 25, 2016 · 13 comments

Comments

@sheymann
Copy link

Hello,

I chain queries as follows. The last one returns an error 400 with a JSON object in response that provides detailed information. This response should be available in the last catch but it is undefined, as well as the xhr object:

var qwestOpts = {
  cache: true,
  withCredentials: true
};

qwest.post(..., {...}, qwestOpts)

.then(function() {
  return qwest.get(..., null, qwestOpts);
})

.then(function(xhr, response) {
  ...
  return qwest.post(..., {...}, qwestOpts);
})

.then(function(xhr, response) {
  ...
  return qwest.post(..., {...}, qwestOpts) // throws error 400 (Bad Request)
})

.then(...)
.catch(function(error, xhr, response) {...}); // xhr === response === undefined

Tested using v4.1.1

@pyrsmk
Copy link
Owner

pyrsmk commented Feb 25, 2016

Are you catching the good error argument as expected?

@sheymann
Copy link
Author

What do you mean?

@pyrsmk
Copy link
Owner

pyrsmk commented Feb 25, 2016

In the last catch, xhr and response are undefined. But what's the state of error, which is the first parameter of catch?

@sheymann
Copy link
Author

Error is equal to the string "400 (Bad Request)"

@pyrsmk
Copy link
Owner

pyrsmk commented Feb 25, 2016

Which one? xD

@sheymann
Copy link
Author

The error parameter of the last catch :)

@pyrsmk
Copy link
Owner

pyrsmk commented Feb 25, 2016

You gave me two different errors, which one is the error parameter? :p
And where is from the other one?

@sheymann
Copy link
Author

Of I've erased the first error on the comments because it was a mistake, there is a one error only.

@pyrsmk
Copy link
Owner

pyrsmk commented Feb 25, 2016

Ah! My bad, I should have refresh the page ;)

So the good error is catched, it's just the arguments that are not valid. I'll look that tomorrow!

@sheymann
Copy link
Author

Thanks!

@pyrsmk
Copy link
Owner

pyrsmk commented Mar 14, 2016

I think this is not a bug but the internal behavior of PinkySwear, the library that qwest uses for its promises layer. Since an error is thrown in a then, PinkySwear throws the error to the next catch without telling it to qwest. For this to work, I should wrap the then promise and add a try-catch block.

@pyrsmk
Copy link
Owner

pyrsmk commented Mar 14, 2016

Then, I think I can't deal with this issue because I can't see a way to deal with the PinkySwear's internal routines.

Can't you use the grouped requests as described in the documentation?

@pyrsmk
Copy link
Owner

pyrsmk commented Mar 27, 2016

I'm closing this for idling ;)

@pyrsmk pyrsmk closed this as completed Mar 27, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants