class Revolut::Error
Base Revolut
error.
Public Class Methods
error_class(status)
click to toggle source
rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
# File lib/revolut/error.rb, line 31 def self.error_class(status) case status when 400 then Revolut::BadRequest when 401 then Revolut::Unauthorized when 403 then Revolut::Forbidden when 404 then Revolut::NotFound when 405 then Revolut::MethodNotAllowed when 406 then Revolut::NotAcceptable when 429 then Revolut::TooManyRequests when 500 then Revolut::InternalServerError when 503 then Revolut::ServiceUnavailable end end
error_message(response)
click to toggle source
Returns the appropriate Revolut
error message based on response
@param response [Faraday::Env] HTTP response.
@return [String] Revolut
error message.
# File lib/revolut/error.rb, line 51 def self.error_message(response) return unless response.body.is_a?(Hash) message = response.body['message'] return unless message Revolut::Utils.presence(message) end
from_response(response)
click to toggle source
Returns the appropriate Revolut::Error
sublcass based on status and response message.
@param response [Faraday::Env] HTTP response.
@return [Revolut::Error]
# File lib/revolut/error.rb, line 22 def self.from_response(response) status = response.status.to_i message = error_message(response) klass = error_class(status) klass&.new(message) end
new(msg = nil)
click to toggle source
Calls superclass method
# File lib/revolut/error.rb, line 6 def initialize(msg = nil) super(msg) @message = msg end
Public Instance Methods
to_s()
click to toggle source
Default error message.
Calls superclass method
# File lib/revolut/error.rb, line 12 def to_s @message || super end