HttpClient 'Http failure during parsing' error for valid json
See original GitHub issueI’m submitting a…
[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] 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
Request throws an error when trying to parse a response of "ok"
which is considered valid json according to https://jsonlint.com/
request:
const requestOptions = Object.assign(
{},
{ responseType: 'json' },
{ observe: 'body' as HttpObserve }
);
this.httpClient.request('GET', './mockjson.json', requestOptions)
...
error: "Unexpected token o in JSON at position 0"
Expected behavior
No error should be thrown for a response of "ok"
Minimal reproduction of the problem with instructions
https://embed.plnkr.co/klPNUS/
What is the motivation / use case for changing the behavior?
Environment
Angular version: 4.3.2
Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
For Tooling issues:
- Node version: XX
- Platform:
Others:
Issue Analytics
- State:
- Created 6 years ago
- Reactions:8
- Comments:25 (3 by maintainers)
Top Results From Across the Web
Angular HttpClient "Http failure during parsing" - Stack Overflow
You can specify that the data to be returned is not JSON using responseType . In your example, you can use a responseType...
Read more >How-to Fix "Http failure during parsing" Error
Three possible reasons for the "Http failure during parsing for" error in Angular HttpClient and some ... Validate it via JSON validator ...
Read more >Angular 9 Httperrorresponse 'Json.Parse Error ... - ADocLib
HttpClient 'Http failure during parsing' error for valid json #18396 Request throws an error when trying to parse a response of ok which...
Read more >Angular HttpClient “Http failure during parsing” - iTecNote
You can specify that the data to be returned is not JSON using responseType . In your example, you can use a responseType...
Read more >How-to Fix "Http failure during parsing" Error - Morioh
Three possible reasons for the "Http failure during parsing for" error in Angular HttpClient and some ideas about how to fix them.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
this.http.get(url, {responseType: ‘text’})
it works as well.
Ran into same problem making a
put
request to my endpoint. I realized I was sending 200 without a response body. Sending status code204
made angular http 5.2.8 stop complaining. This problem should not be happening even with a 200, but 204 is the correct code for empty responses.