class RubyTCC::Error

Custom error class for rescuing from all RubyTCC errors

Constants

ClientError

Raised when RubyTCC returns a 4xx HTTP status code

ConfigurationError
RequestTimeout

Raised when RubyTCC returns the HTTP status code 408

ResultError

Raised when the result is not “Success”

Attributes

code[R]

@return [Integer]

Public Class Methods

from_response(response) click to toggle source

Create a new error from an HTTP response

@param response [RestClient::Response] @return [RubyTCC::Error]

# File lib/rubytcc/error.rb, line 12
def from_response(response)
  message, code = parse_error(response.body)
  new(message, response.response_headers, code)
end
new(message = '', code = nil) click to toggle source

Initializes a new Error object

@param message [Exception, String] @param code [Integer] @return [RubyTCC::Error]

Calls superclass method
# File lib/rubytcc/error.rb, line 44
def initialize(message = '', code = nil)
  super(message)
  @code = code
end

Private Class Methods

extract_message_from_errors(body) click to toggle source
# File lib/rubytcc/error.rb, line 29
def extract_message_from_errors(body)
  first = Array(body[:errors]).first
  if first.is_a?(Hash)
    [first[:message].chomp, first[:code]]
  else
    [first.chomp, nil]
  end
end
parse_error(body) click to toggle source
# File lib/rubytcc/error.rb, line 19
def parse_error(body)
  if body.nil?
    ['', nil]
  elsif body[:error]
    [body[:error], nil]
  elsif body[:errors]
    extract_message_from_errors(body)
  end
end