Module: Airbrake::Response Private
- Extended by:
- Loggable
- Defined in:
- lib/airbrake-ruby/response.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Parses responses coming from the Airbrake API. Handles HTTP errors by logging them.
Constant Summary collapse
- TRUNCATE_LIMIT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns the limit of the response body.
100
- BAD_REQUEST =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns HTTP code returned when the server cannot or will not process the request due to something that is perceived to be a client error.
400
- UNAUTHORIZED =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns HTTP code returned when client request has not been completed because it lacks valid authentication credentials for the requested resource.
401
- FORBIDDEN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns HTTP code returned when the server understands the request but refuses to authorize it.
403
- REQUEST_TIMEOUT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns HTTP code returned when the server would like to shut down this unused connection.
408
- CONFLICT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns HTTP code returned when there’s a request conflict with the current state of the target resource.
409
- ENHANCE_YOUR_CALM =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
420
- TOO_MANY_REQUESTS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns HTTP code returned when an IP sends over 10k/min notices.
429
- INTERNAL_SERVER_ERROR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns HTTP code returned when the server encountered an unexpected condition that prevented it from fulfilling the request.
500
- BAD_GATEWAY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns HTTP code returened when the server, while acting as a gateway or proxy, received an invalid response from the upstream server.
502
- GATEWAY_TIMEOUT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns HTTP code returened when the server, while acting as a gateway or proxy, did not get a response in time from the upstream server that it needed in order to complete the request.
504
Class Method Summary collapse
-
.parse(response) ⇒ Hash{String=>String}
private
Parses HTTP responses from the Airbrake API.
Methods included from Loggable
Class Method Details
.parse(response) ⇒ Hash{String=>String}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parses HTTP responses from the Airbrake API.
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/airbrake-ruby/response.rb', line 70 def self.parse(response) code = response.code.to_i body = response.body begin case code when 200, 204 logger.debug("#{LOG_LABEL} #{name} (#{code}): #{body}") { response.msg => response.body } when 201 parsed_body = JSON.parse(body) logger.debug("#{LOG_LABEL} #{name} (#{code}): #{parsed_body}") parsed_body when BAD_REQUEST, UNAUTHORIZED, FORBIDDEN, ENHANCE_YOUR_CALM parsed_body = JSON.parse(body) logger.error("#{LOG_LABEL} #{parsed_body['message']}") parsed_body.merge('code' => code, 'error' => parsed_body['message']) when TOO_MANY_REQUESTS parsed_body = JSON.parse(body) msg = "#{LOG_LABEL} #{parsed_body['message']}" logger.error(msg) { 'code' => code, 'error' => msg, 'rate_limit_reset' => rate_limit_reset(response), } else body_msg = truncated_body(body) logger.error("#{LOG_LABEL} unexpected code (#{code}). Body: #{body_msg}") { 'code' => code, 'error' => body_msg } end rescue StandardError => ex body_msg = truncated_body(body) logger.error("#{LOG_LABEL} error while parsing body (#{ex}). Body: #{body_msg}") { 'code' => code, 'error' => ex.inspect } end end |