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
HttpClient should allow different responseTypes for success response and error response #19148
Comments
|
This would be really great! I have a Spring Service that usually returns an Excel file (HttpClient uses responseType 'blob'), but might return JSON with error details if the generation fails. In case of an Error the HttpErrorResponse.error is undefined when handling it in HttpInterceptor, so I cannot use the additional informations returned by the Backend. I don't see any good workaround for doing this now:
So both thumbs up for this feature request! |
|
A year later with Angular 6 still an issue. In my opinion this is a bug, not a feature. |
|
Any news on this? |
|
@trotyl See this example. This returns a This works if the request is successful. However, in case of exception thrown from the Spring handler method, the body is set to The Spring |
|
@lppedd I see your case now, but the problem is, what Angular did is just pass The |
|
@trotyl I "temporary" solved by integrating a blob > string transformation. Do you think Angular will ever introduce the |
|
@lppedd I'd rather Angular drop the entire |
|
Hello again in 2020, I have this issue but cannot use the temporary solution described here. The problem is I want to synchronously get the error to check if the jwt token really got expired and do a |
|
Also have had an issue with this. I will try workaround for now. |
|
isn't the success type solved with the generic HttpClient we got a while back? https://angular.io/api/common/http/HttpClient#get That at least solves it for me. However the error response type is still Keep in mind that each http return code could return a different type. Http return code 400 and 500 probably doesn't have the same format. |
|
My workaround is to add an interceptor with: |
Worked like a charm, thank you so much! It would be great if Angular would have such a feature where you can set different response types for success or error responses. |
|
For me, I use a synchronous way to convert Blob to json. I wrote a post about it here: https://stackoverflow.com/questions/48500822/how-to-handle-error-for-response-type-blob-in-httprequest/70977054#70977054 This is how it works: The parsed |
|
Hello in 2022. This is still a problem, 5 years later... |
|
Hello in 2023 |




I'm submitting a...
Current behavior
Currently, HttpClient expects the same responseType for both, success responses as well as error responses. This brings up issues when a WEB API returns e. g. JSON but just an (non JSON based) error string in the case of an error.
Expected behavior
In see two solutions: Provide an own errorResponseType field or assign the received message as a string when JSON parsing does not work (as a fallback)
Minimal reproduction of the problem with instructions
The following test case is using such an Web API. It returns json for the success case and plain text in the case of an error. Both tests lead to an 400 error due to validation issues. In the first case where we are requesting plain text, the text based error message is shown; in the second case where we are requesting json (which would be the case if the call succeeded) we are just getting null.
What is the motivation / use case for changing the behavior?
Using existing Web APIs more seamlessly
Environment
The text was updated successfully, but these errors were encountered: