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.

Since:

  • v1.0.0

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.

Returns:

  • (Integer)

    the limit of the response body

Since:

  • v1.0.0

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.

Returns:

  • (Integer)

    HTTP code returned when the server cannot or will not process the request due to something that is perceived to be a client error

Since:

  • v6.2.0

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.

Returns:

  • (Integer)

    HTTP code returned when client request has not been completed because it lacks valid authentication credentials for the requested resource

Since:

  • v6.2.0

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.

Returns:

  • (Integer)

    HTTP code returned when the server understands the request but refuses to authorize it

Since:

  • v6.2.0

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.

Returns:

  • (Integer)

    HTTP code returned when the server would like to shut down this unused connection

Since:

  • v6.2.0

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.

Returns:

  • (Integer)

    HTTP code returned when there’s a request conflict with the current state of the target resource

Since:

  • v6.2.0

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.

Returns:

  • (Integer)

Since:

  • v6.2.0

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.

Returns:

  • (Integer)

    HTTP code returned when an IP sends over 10k/min notices

Since:

  • v1.0.0

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.

Returns:

  • (Integer)

    HTTP code returned when the server encountered an unexpected condition that prevented it from fulfilling the request

Since:

  • v6.2.0

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.

Returns:

  • (Integer)

    HTTP code returened when the server, while acting as a gateway or proxy, received an invalid response from the upstream server

Since:

  • v6.2.0

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.

Returns:

  • (Integer)

    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

Since:

  • v6.2.0

504

Class Method Summary collapse

Methods included from Loggable

logger

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

Parameters:

  • response (Net::HTTPResponse)

Returns:

  • (Hash{String=>String})

    parsed response

Since:

  • v1.0.0



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