node-spotify-webhelper icon indicating copy to clipboard operation
node-spotify-webhelper copied to clipboard

Gracefully handle 503

Open roncli opened this issue 7 years ago • 2 comments
trafficstars

Occasionally, the Web Helper will throw a "503 Service Temporarily Unavailable". In that case, the response body from the Web Helper is:

<html>
<head><title>503 Service Temporarily Unavailable</title></head>
<body bgcolor="white">
<center><h1>503 Service Temporarily Unavailable</h1></center>
<hr><center>nginx</center>
</body>
</html>
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->

The library then attempts to parse this as JSON, fails, and throws the resulting SyntaxError: Unexpected token < in JSON at position 0. Unfortunately, the call does not get the entire body, so the client never knows that this was due to a 503 on the Web Helper.

These Web Helper errors tend to be transient, and usually go away on the next call.

This request is to more gracefully handle non-success HTTP results from the Web Helper. My solution would be to create my own error class that extends Error to indicate there was some kind of error with the Web Helper, and return the status code and content with the Error.

roncli avatar Dec 19 '17 08:12 roncli

Thanks for reporting this issue, I'll be happy to accept a pull request with a fix to this issue

nadavbar avatar Dec 19 '17 08:12 nadavbar

Cool. I'll try to write something up before the weekend. :)

roncli avatar Dec 19 '17 08:12 roncli