Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix($http): allow empty json response #9562

Closed
wants to merge 1 commit into from

Conversation

tbosch
Copy link
Contributor

@tbosch tbosch commented Oct 10, 2014

When a response contains an application/json header and
the response is empty the response should be left as is.

Fixes #9532

When a response contains an `application/json` header and
the response is empty the response should be left as is.

Fixes angular#9532
@tbosch tbosch added this to the 1.3.0-rc.6 milestone Oct 10, 2014
@@ -771,7 +771,7 @@ function $HttpProvider() {
function transformResponse(response) {
// make a copy since the response must be cacheable
var resp = extend({}, response);
if(config.method === 'HEAD'){
if (!response.data) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we maybe special case 204 and HEAD, and just set the value to undefined instead?

if (!response.data && (config.method === 'HEAD' || response.status === 204)) {
  delete resp.data; // or resp.data = undefined;
}

Because really, an empty JSON string is a programming error in other cases.

Up to you guys though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IgorMinar What do you think?

@tbosch tbosch closed this Oct 10, 2014
@tbosch tbosch deleted the fix/emptyhttp branch October 10, 2014 20:17
tbosch added a commit that referenced this pull request Oct 10, 2014
When a response contains an `application/json` header and
the response is empty the response should be left as is.

Fixes #9532
Closes #9562
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exception thrown for empty 204 HTTP response
3 participants