-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Obtain response on ajax() call, even if there's a 404 #2059
Comments
@rgbkrk seems to work for me? http://jsbin.com/duwuwi/edit?js,console Perhaps I'm confused? Is there something subtly different in your project that's not the same as the provided example? For example, the browser won't automatically parse the response JSON if the server didn't say the response |
Well, I did run a @rgbkrk plays with the jsbin for a bit based on your example Now I see. In order to make .catch(err => Observable.of(err.xhr)) |
Now that I see how to use this, it makes me wish I posted this as a StackOverflow issue instead. 😉 For the sake of me helping others in open source, around the web, and on my team - what's the reasoning behind making 404s and others turn into errors? |
@rgbkrk ohhh I think I see, you're talking about the fact that error vs non-error objects differ // error
{
message: "ajax error 404",
status: 404,
xhr: { ... },
request: { ... }
}
// success
{
status: 200,
xhr: { ... },
request: { ... },
response: { ... },
responseType: "json",
originalEvent: { ... }
} It's not immediately clear if this is intentional or if just an oversight. I can't see any problem with having the response stuff on the top-level error object. |
Do you mean why is it an exception you have to catch or why is does the exception not have the response at the top level like the success object does? |
Yes. |
If the response was in the top-level object I certainly wouldn't have gone to the documentation or issues, I would have just passed it on with a |
I don't have true backstory on why, but I can make several guesses: v4 did it that way and no one has likely challenged it recently AFAICT. Also that this is common for ajax utils, e.g. That said, the
I think which one a person prefers really depends on the person and the use case. Most of the time a non-200 really is exceptional and I personally prefer the exception path for these because then my "happy path" isn't cluttered with error checks and also if I don't have some way to recover from the error I can not catch it, letting it propagate and catch in a single place to log (or the console) instead of it going down the happy path, causing a reference error and losing what would have been on the error object--so then errors logged are ambiguous. This is probably all debatable though. We might, for instance, default to similar to behavior as |
That makes perfect sense. In terms of ideal Rx flows, |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
RxJS version:
5.0.0-rc.1
Code to reproduce:
Expected behavior:
On a 404, I expect to be able to get the payload/response. With the "API" I used above, I'd want to have:
With
fetch
I get the response.Actual behavior:
Result, that can be
.caught
, is anAjaxError
and has rough structure (note no response):I want the response body. Is there any way to surface it?
The text was updated successfully, but these errors were encountered: