Skip to content
New issue

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

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

Already on GitHub? # to your account

More Descriptive Error Message On Http 200 But No JSON #944

Merged
merged 3 commits into from
Mar 17, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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