karbassi / netatmo

A node.js module to hook into the netatmo API.
MIT License
58 stars 45 forks source link

Prevent a crash when netatmo error body contains HTML and not JSON #7

Closed danilowanner closed 8 years ago

danilowanner commented 9 years ago

I had to make another small change.

Sometimes netatmo fails to return JSON when an error occurs. Previously this caused the package to crash. The change should remedy this.

karbassi commented 9 years ago

@danilowanner Can we check to see when it returns JSON and when it returns HTML. We need to convert to JSON when needed.

danilowanner commented 9 years ago

I thought about that. We could try and parse JSON and if it fails catch the error. But since we are going to display an error, we convert to a string anyways right afterwards.

The node console would show the following, if we were to log the parsed JSON: [Error: [object Object]]

When we log the body directly we get: [Error: {"error":{"code":404,"message":"Not Found"}}]

karbassi commented 8 years ago

Fixed in #12