bartve / disconnect

An easy to use Node.js client with OAuth support to connect with the discogs.com API v2.0
MIT License
453 stars 79 forks source link

Fixed crash if discogs servers respond with html #13

Closed joeyfromspace closed 9 years ago

joeyfromspace commented 9 years ago

Hey there,

Thanks for writing disconnect. It's very useful and elegantly built.

I did run into a problem when Discogs went into maintenance mode which was causing my app to crash every time it got a response from the server.

I looked into it and it's because you were running JSON.parse() on html.

My change is a simple amendment to the if statement after the server response to make sure it's not an html page.

Cheers and thanks again for this awesome module!

bartve commented 9 years ago

You're welcome :) Just out of curiosity (Discogs downtime was at night in my timezone), what kind of HTML did the Discogs API return during downtime? I would have expected an empty response or some generic json formatted message with matching HTTP headers...

joeyfromspace commented 9 years ago

I didn't check the HTTP response directly myself or read the full response (before their servers came up), but what I got was the beginning of an html doc...I am guessing a 404 page? I've encountered this with PayPal's API before when they're having technical problems.

Here's the fragment thrown by Node's exception:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/

bartve commented 9 years ago

Ah ok, thanks for checking. Probably just the load balancer sending a generic html 404 page. Thanks for the notification and fix. A new release with this fix + some other minor things has been published.