Skip to content

HttpClient issue when request may return 202 with json or 204 #19413

@karptonite

Description

@karptonite

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

For HttpRequests that may return either a 20x with json or 204 No Content response, it is awkward to set the headers in a way that makes sense. If you use the defaults, a 204 will error because the result body, an empty string, cannot be parsed to JSON. If you set the contentType to 'text', you can avoid that error, but then have to manually call parse on the responses that have content.

Expected behavior

Not sure. One alternative is to have some option to indicate that the response body is optional, and return null if it is not set. Another would be to recognize that 204 responses have no content, and not try to parse them--the return type might still be an issue, though.

What is the motivation / use case for changing the behavior?

The motivating case here is an http patch request, for which rfc 5789 suggests returning 204 if the patch was applied, and also allows other status codes, such as 202 Accepted, which should include in the body information on how to check the progress of the request.

This is also somewhat related to issue #19090, another case in which it should be clear from the request (instead of, in the current case, the response code) that there should be no body.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions