question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HttpClient 'Http failure during parsing' error for valid json

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Reactions:8
  • Comments:25 (3 by maintainers)

github_iconTop GitHub Comments

142reactions
dyh333commented, Oct 17, 2017

this.http.get(url, {responseType: ‘text’})

it works as well.

9reactions
leojkwancommented, Mar 18, 2018

Ran into same problem making a put request to my endpoint. I realized I was sending 200 without a response body. Sending status code 204 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found