Skip to content
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
16 changes: 8 additions & 8 deletions lib/hawk/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def response_handler(response)
req = response.request
url = req.url
meth = req.options.fetch(:method).to_s.upcase
it = [meth, url].join(' ')
req_info = "#{meth} #{url}"

if response.timed_out?
what, secs = if response.connect_time&.zero?
Expand All @@ -135,24 +135,24 @@ def response_handler(response)
[:request, req.options[:timeout]]
end

raise Error::Timeout, "#{it}: #{what} timed out after #{secs} seconds"
raise Error::Timeout, "#{req_info}: #{what} timed out after #{secs} seconds"
end

case (code = response.response_code)
when 0
raise Error::Empty, "#{it}: Empty response from server (#{response.status_message})"
raise Error::Empty, "#{req_info}: Empty response from server (#{response.status_message})"
when 400
raise Error::BadRequest, "#{it} was a bad request"
raise Error::BadRequest, "#{req_info} was a bad request"
when 403
raise Error::Forbidden, "#{it} denied access"
raise Error::Forbidden, "#{req_info} denied access"
when 404
raise Error::NotFound, "#{it} was not found"
raise Error::NotFound, "#{req_info} was not found"
when 500
raise Error::InternalServerError, "#{it}: Server error (#{response.body[0..120]})"
raise Error::InternalServerError, "#{req_info}: Server error (#{response.body[0..120]})"
else
app_error = parse_app_error_from(response.body)

raise Error::HTTP.new(code, "#{it} failed with error #{code} (#{response.status_message}): #{app_error}")
raise Error::HTTP.new(code, "#{req_info} failed with error #{code} (#{response.status_message}): #{app_error}")
end
end

Expand Down