class Teamsupport::Error
Custom error class for rescuing from all Teamsupport
errors
Constants
- BadGateway
Raised when
Teamsupport
returns the HTTP status code 502- BadRequest
Raised when
Teamsupport
returns the HTTP status code 400- ClientError
Raised when
Teamsupport
returns a 4xx HTTP status code- ERRORS
- Forbidden
Raised when
Teamsupport
returns the HTTP status code 403- GatewayTimeout
Raised when
Teamsupport
returns the HTTP status code 504- InternalServerError
Raised when
Teamsupport
returns the HTTP status code 500- NotAcceptable
Raised when
Teamsupport
returns the HTTP status code 406- NotFound
Raised when
Teamsupport
returns the HTTP status code 404- ServerError
Raised when
Teamsupport
returns a 5xx HTTP status codeRaised when
Teamsupport
returns the HTTP status code 503- TooManyRequests
Raised when
Teamsupport
returns the HTTP status code 429Raised when
Teamsupport
returns the HTTP status code 401- UnprocessableEntity
Raised when
Teamsupport
returns the HTTP status code 422
Attributes
Provide a code method for reading HTTP status code from Error
@example
teamsupport_error = Teamsupport::Error.new(code: 404) teamsupport_error.code
@return [Integer]
@api public
Public Class Methods
Create a new error from an HTTP response
@example
teamsupport_error = Teamsupport::Error::ERRORS[code] teamsupport_error.from_response(body, headers) unless klass.nil?
@param body [String] @param headers [Hash]
@return [Teamsupport::Error]
@api public
# File lib/teamsupport/error.rb, line 81 def from_response(body, _headers) message, code = parse_error(body) new(message, code) end
Initializes a new Error
object
@param message [Exception, String] @param code [Integer]
@return [Teamsupport::Error]
@api private
# File lib/teamsupport/error.rb, line 130 def initialize(message = '', code = nil) super(message) @code = code end
Private Class Methods
Extracts error messages from response body
@param body [String]
@return [Array]
@api private
# File lib/teamsupport/error.rb, line 112 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
Parses response body for errors
@param body [String]
@return [Array, nil]
@api private
# File lib/teamsupport/error.rb, line 95 def parse_error(body) if body.nil? || body.empty? ['', nil] elsif body[:error] [body[:error], nil] elsif body[:errors] extract_message_from_errors(body) end end