class Honeybadger::Backend::Response
Constants
- FRIENDLY_ERRORS
- NOT_BLANK
Attributes
body[R]
code[R]
error[R]
message[R]
Public Class Methods
new(*args)
click to toggle source
Initializes the Response
instance.
@overload initialize(response) Creates an instance from a Net::HTTPResponse
. @param [Net::HTTPResponse] response With 1 argument, the code, body, and message will be determined automatically.
@overload initialize(code, body, message) Creates an instance from parameters. @param [Integer] code The status code. May also be :error for requests which failed to reach the server. @param [String] body The String body of the response. @param [String] message The String message returned by the server (or set by the backend in the case of an :error code).
# 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
Public Instance Methods
error_message()
click to toggle source
# 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?()
click to toggle source
# File lib/honeybadger/backend/base.rb, line 46 def success? @success end
Private Instance Methods
parse_error(body)
click to toggle source
# File lib/honeybadger/backend/base.rb, line 61 def parse_error(body) return unless body =~ NOT_BLANK obj = JSON.parse(body) return obj['error'] if obj.kind_of?(Hash) rescue JSON::ParserError nil end