Skip to content

Commit

Permalink
More verbose error printing if the body is not JSON
Browse files Browse the repository at this point in the history
Recently could have saved me a bunch of time when GitHub
returned an authorization error, which does not follow
the usual JSON format.
  • Loading branch information
Keno committed Jan 30, 2018
1 parent 33e3dd4 commit efef36f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/utils/requests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,19 @@ end
function handle_response_error(r::HTTP.Response)
if r.status >= 400
message, docs_url, errors = "", "", ""
body = HTTP.load(r)
try
data = JSON.parse(HTTP.load(r))
data = JSON.parse(body)
message = get(data, "message", "")
docs_url = get(data, "documentation_url", "")
errors = get(data, "errors", "")
end
error("Error found in GitHub reponse:\n",
"\tStatus Code: $(r.status)\n",
"\tMessage: $message\n",
"\tDocs URL: $docs_url\n",
"\tErrors: $errors")
((isempty(message) && isempty(errors)) ?
("\tBody: $body",) :
("\tMessage: $message\n",
"\tDocs URL: $docs_url\n",
"\tErrors: $errors"))...)
end
end

0 comments on commit efef36f

Please sign in to comment.