Skip to content

Commit

Permalink
Merge pull request #944 from HubSpot/more-descriptive-error-on-http-2…
Browse files Browse the repository at this point in the history
…00-no-json

More Descriptive Error Message On Http 200 But No JSON
  • Loading branch information
ssalinas committed Mar 17, 2016
2 parents 9960b29 + fbe408a commit d7cc7f4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions SingularityUI/app/application.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,16 @@ class Application
message: "<p>Could not reach the Singularity API. Please make sure SingularityUI is properly set up.</p><p>If running through Brunch, this might be your browser blocking cross-domain requests.</p>"
else
try
serverMessage = JSON.parse(jqxhr.responseText).message or jqxhr.responseText
serverMessage = JSON.parse(jqxhr.responseText).message or jqxhr.responseText
catch
serverMessage = jqxhr.responseText
if jqxhr.status is 200
console.error jqxhr.responseText
Messenger().error
message: """
<p>Expected JSON but received #{if jqxhr.responseText.startsWith '<!DOCTYPE html>' then 'html' else 'something else'}. The response has been saved to your js console.</p>
"""
throw new Error "Expected JSON in response but received #{if jqxhr.responseText.startsWith '<!DOCTYPE html>' then 'html' else 'something else'}"
serverMessage = jqxhr.responseText

serverMessage = _.escape serverMessage
id = "message_" + Date.now()
Expand Down

0 comments on commit d7cc7f4

Please # to comment.