Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle 503 #14

Open
roncli opened this issue Dec 19, 2017 · 2 comments
Open

Gracefully handle 503 #14

roncli opened this issue Dec 19, 2017 · 2 comments

Comments

@roncli
Copy link

roncli commented Dec 19, 2017

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.

@nadavbar
Copy link
Owner

nadavbar commented Dec 19, 2017

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

@roncli
Copy link
Author

roncli commented Dec 19, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants