Exception: Astroapi::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Astroapi::Error
- Defined in:
- lib/astroapi/error.rb
Overview
Base error class for all Astroapi errors
Direct Known Subclasses
ClientError, ConfigurationError, ConnectionError, ServerError, TimeoutError, ValidationError
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Class Method Summary collapse
-
.from_faraday_error(error) ⇒ Astroapi::Error
Convert a Faraday error to an Astroapi error.
Instance Method Summary collapse
-
#client_error? ⇒ Boolean
Check if error is a client error (4xx).
-
#initialize(message, status_code: nil, code: nil, details: nil, response: nil) ⇒ Error
constructor
A new instance of Error.
-
#server_error? ⇒ Boolean
Check if error is a server error (5xx).
Constructor Details
#initialize(message, status_code: nil, code: nil, details: nil, response: nil) ⇒ Error
Returns a new instance of Error.
8 9 10 11 12 13 14 |
# File 'lib/astroapi/error.rb', line 8 def initialize(, status_code: nil, code: nil, details: nil, response: nil) super() @status_code = status_code @code = code @details = details @response = response end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/astroapi/error.rb', line 6 def code @code end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
6 7 8 |
# File 'lib/astroapi/error.rb', line 6 def details @details end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
6 7 8 |
# File 'lib/astroapi/error.rb', line 6 def response @response end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
6 7 8 |
# File 'lib/astroapi/error.rb', line 6 def status_code @status_code end |
Class Method Details
.from_faraday_error(error) ⇒ Astroapi::Error
Convert a Faraday error to an Astroapi error
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/astroapi/error.rb', line 35 def self.from_faraday_error(error) case error when Faraday::TimeoutError TimeoutError.new(error., details: error) when Faraday::ConnectionFailed ConnectionError.new(error., details: error) when Faraday::ServerError status = error.response&.dig(:status) body = error.response&.dig(:body) ServerError.new(error., status_code: status, response: body, details: error) when Faraday::ClientError status = error.response&.dig(:status) body = error.response&.dig(:body) ClientError.new(error., status_code: status, response: body, details: error) else status = error.respond_to?(:response) ? error.response&.dig(:status) : nil body = error.respond_to?(:response) ? error.response&.dig(:body) : nil new(error., status_code: status, response: body, details: error) end end |
Instance Method Details
#client_error? ⇒ Boolean
Check if error is a client error (4xx)
18 19 20 21 22 |
# File 'lib/astroapi/error.rb', line 18 def client_error? return false unless status_code status_code >= 400 && status_code < 500 end |
#server_error? ⇒ Boolean
Check if error is a server error (5xx)
26 27 28 29 30 |
# File 'lib/astroapi/error.rb', line 26 def server_error? return false unless status_code status_code >= 500 && status_code < 600 end |