Exception: Revolut::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Revolut::Error
- Defined in:
- lib/revolut/error.rb
Overview
Base Revolut error.
Direct Known Subclasses
BadRequest, Forbidden, InternalServerError, MethodNotAllowed, NotAcceptable, NotFound, ServiceUnavailable, TooManyRequests, Unauthorized
Class Method Summary collapse
-
.error_class(status) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength.
-
.error_message(response) ⇒ String
Returns the appropriate Revolut error message based on response.
-
.from_response(response) ⇒ Revolut::Error
Returns the appropriate Revolut::Error sublcass based on status and response message.
Instance Method Summary collapse
-
#initialize(msg = nil) ⇒ Error
constructor
A new instance of Error.
-
#to_s ⇒ Object
Default error message.
Constructor Details
#initialize(msg = nil) ⇒ Error
Returns a new instance of Error.
6 7 8 9 |
# File 'lib/revolut/error.rb', line 6 def initialize(msg = nil) super(msg) @message = msg end |
Class Method Details
.error_class(status) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# 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) ⇒ String
Returns the appropriate Revolut error message based on response
51 52 53 54 55 56 57 58 |
# File 'lib/revolut/error.rb', line 51 def self.(response) return unless response.body.is_a?(Hash) = response.body['message'] return unless Revolut::Utils.presence() end |
.from_response(response) ⇒ Revolut::Error
Returns the appropriate Revolut::Error sublcass based on status and response message.
22 23 24 25 26 27 28 |
# File 'lib/revolut/error.rb', line 22 def self.from_response(response) status = response.status.to_i = (response) klass = error_class(status) klass&.new() end |
Instance Method Details
#to_s ⇒ Object
Default error message.
12 13 14 |
# File 'lib/revolut/error.rb', line 12 def to_s @message || super end |