-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Http: naked false/0 value is not correctly parsed when using json as response type #19825
Copy link
Copy link
Closed
Closed
Copy link
Labels
area: common/httpIssues related to HTTP and HTTP ClientIssues related to HTTP and HTTP Clientfreq1: lowtype: bug/fix
Description
I'm submitting a...
[X] Bug reportCurrent behavior
http.get<boolean>(`/api/canYouSeeMe`)
.subscribe(x => console.log(x));In such case if backend returns false or 0 straight in the body (without any nested object) the console print outs null. While true or 1 keeps what it is.
Yes. I know that it's strongly recommended for json APIs to return pure values wrapped into some object, but still.. it's not forbidden and seems like javascript supports parsing such values.
And that's happening because of this line:
angular/packages/common/http/src/response.ts
Line 265 in 230b98d
| this.body = init.body || null; |
Obviously:
this.body = true || null; // true
this.body = false || null; // null
this.body = 0 || null; // nullExpected behavior
Keep the falsy (false, 0) value unchanged.
Current workaround
Set the responseType to text and parse it for yourself.
Environment
Angular versions: 4.x, 5.0.0-rc.3Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area: common/httpIssues related to HTTP and HTTP ClientIssues related to HTTP and HTTP Clientfreq1: lowtype: bug/fix