Skip to content

Handle unparseable JSON response for API requests#17

Open
stensrud wants to merge 2 commits intogeckoboard:masterfrom
stensrud:json-catch
Open

Handle unparseable JSON response for API requests#17
stensrud wants to merge 2 commits intogeckoboard:masterfrom
stensrud:json-catch

Conversation

@stensrud
Copy link

worker-1 (err): SyntaxError: Unexpected end of input
worker-1 (err):     at Object.parse (native)
worker-1 (err):     at Request.callback [as _callback] (/srv/sites/prod/worker/gameengine/node_modules/geckoboard/lib/api-request.js:14:29)
worker-1 (err):     at Request.self.callback (/srv/sites/prod/worker/gameengine/node_modules/geckoboard/node_modules/request/request.js:187:22)

Getting these in our production environment. This pull request wraps a try/catch around JSON parsing to avoid uncaught errors crashing the server.

@holm
Copy link

holm commented Sep 22, 2017

With todays problems, this happened again: https://geckoboard.statuspage.io/incidents/ltjvjyt9yts0

Would be good to fix this so meaningful error messages can be seen in case of issues with the api.

t-o-m- added a commit that referenced this pull request Nov 8, 2017
fixes issues address here #17
with additional tests
t-o-m- added a commit that referenced this pull request Nov 8, 2017
fixes issues addressed here #17
with additional tests
t-o-m- added a commit that referenced this pull request Nov 8, 2017
fixes issues addressed here #17
with additional tests
t-o-m- added a commit that referenced this pull request Nov 8, 2017
fixes issues addressed here #17
with additional tests
@t-o-m-
Copy link
Contributor

t-o-m- commented Nov 8, 2017

@stensrud thanks for taking the time to look into this issue. A fix has now been merged and released (see #18 - we like our code to have tests, hence the new PR).

cc @holm

@holm
Copy link

holm commented Nov 23, 2017

Thanks for fixing this. I would recommend though that you either log the response body or include it in the error. These things can be very hard to debug when all you have is "Unparseable response" in the error logs. Usually there will be some information in the body, such as a "Gateway failure" or something like that, which helps you understand the nature of the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants