Exception: Lara::LaraApiError
- Defined in:
- lib/lara/errors.rb
Overview
API error with HTTP status, type and message.
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from LaraError
Class Method Summary collapse
-
.from_response(response) ⇒ Object
Builds an error from an HTTP response with JSON body { “type”: “…”, “message”: “…” }.
Instance Method Summary collapse
-
#initialize(status_code, type, message) ⇒ LaraApiError
constructor
A new instance of LaraApiError.
Constructor Details
#initialize(status_code, type, message) ⇒ LaraApiError
Returns a new instance of LaraApiError.
33 34 35 36 37 |
# File 'lib/lara/errors.rb', line 33 def initialize(status_code, type, ) super("(HTTP #{status_code}) #{type}: #{}", status_code) @type = type @message = end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
18 19 20 |
# File 'lib/lara/errors.rb', line 18 def type @type end |
Class Method Details
.from_response(response) ⇒ Object
Builds an error from an HTTP response with JSON body { “type”: “…”, “message”: “…” }.
21 22 23 24 25 26 27 28 |
# File 'lib/lara/errors.rb', line 21 def self.from_response(response) data = begin JSON.parse(response.body) rescue StandardError {} end new(response.status, data["type"] || "UnknownError", data["message"] || "An unknown error occurred") end |