Class: Honeybadger::Backend::Response Private

Inherits:
Object
  • Object
show all
Defined in:
lib/honeybadger/backend/base.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Direct Known Subclasses

Null::StubbedResponse

Constant Summary collapse

NOT_BLANK =

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.

/\S/
FRIENDLY_ERRORS =

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.

{
  429 => "Your project is currently sending too many errors.\nThis issue should resolve itself once error traffic is reduced.".freeze,
  503 => "Your project is currently sending too many errors.\nThis issue should resolve itself once error traffic is reduced.".freeze,
  402 => "The project owner's billing information has expired (or the trial has ended).\nPlease check your payment details or email [email protected] for help.".freeze,
  403 => "The API key is invalid. Please check your API key and try again.".freeze
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response #initialize(code, body, message) ⇒ Response

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.

Initializes the Response instance.

Overloads:

  • #initialize(response) ⇒ Response

    Creates an instance from a Net::HTTPResponse.

    Parameters:

    • response (Net::HTTPResponse)

      With 1 argument, the code, body, and message will be determined automatically.

  • #initialize(code, body, message) ⇒ Response

    Creates an instance from parameters.

    Parameters:

    • code (Integer)

      The status code. May also be :error for requests which failed to reach the server.

    • body (String)

      The String body of the response.

    • message (String)

      The String message returned by the server (or set by the backend in the case of an :error code).


35
36
37
38
39
40
41
42
43
44
# File 'lib/honeybadger/backend/base.rb', line 35

def initialize(*args)
  if (response = args.first).kind_of?(Net::HTTPResponse)
    @code, @body, @message = response.code.to_i, response.body.to_s, response.message
  else
    @code, @body, @message = args
  end

  @success = (200..299).cover?(@code)
  @error = parse_error(body) unless @success
end

Instance Attribute Details

#bodyObject (readonly)

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.


12
13
14
# File 'lib/honeybadger/backend/base.rb', line 12

def body
  @body
end

#codeObject (readonly)

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.


12
13
14
# File 'lib/honeybadger/backend/base.rb', line 12

def code
  @code
end

#errorObject (readonly)

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.


12
13
14
# File 'lib/honeybadger/backend/base.rb', line 12

def error
  @error
end

#messageObject (readonly)

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.


12
13
14
# File 'lib/honeybadger/backend/base.rb', line 12

def message
  @message
end

Instance Method Details

#error_messageObject

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.


50
51
52
53
54
55
56
57
# File 'lib/honeybadger/backend/base.rb', line 50

def error_message
  return message if code == :error
  return FRIENDLY_ERRORS[code] if FRIENDLY_ERRORS[code]
  return error if error =~ NOT_BLANK
  msg = "The server responded with #{code}"
  msg << ": #{message}" if message =~ NOT_BLANK
  msg
end

#success?Boolean

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.

Returns:

  • (Boolean)

46
47
48
# File 'lib/honeybadger/backend/base.rb', line 46

def success?
  @success
end