ijpiantanida / talkback

A simple HTTP proxy that records and playbacks requests
MIT License
283 stars 41 forks source link

fix: handle invalid JSON response #50

Closed rmtsrc closed 3 years ago

rmtsrc commented 3 years ago

Sometimes a server will respond with a "content-type": "application/json" header, but sends text or invalid JSON in the body.

In this case I was receiving an error from talkback: Error handling request SyntaxError: Unexpected token e in JSON at position 0

This PR tries to parse the response as JSON first, if it fails fallback to the rawBody.

ijpiantanida commented 3 years ago

Thank you @SebFlippence. v2.4.1 contains this fix.