Exception: Oktakit::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Oktakit::Error
- Defined in:
- lib/oktakit/error.rb
Overview
Custom error class for rescuing from all Okta errors
Direct Known Subclasses
Class Method Summary collapse
- .error(status) ⇒ Object
-
.from_response(response) ⇒ Oktakit::Error
Returns the appropriate Oktakit::Error subclass based on status and response message.
Instance Method Summary collapse
- #data ⇒ Object
-
#errors ⇒ Array<Hash>
Array of validation errors.
-
#initialize(response = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(response = nil) ⇒ Error
Returns a new instance of Error.
36 37 38 39 |
# File 'lib/oktakit/error.rb', line 36 def initialize(response = nil) @response = response super() end |
Class Method Details
.error(status) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/oktakit/error.rb', line 16 def self.error(status) case status when 400 then Oktakit::BadRequest when 401 then Oktakit::Unauthorized when 403 then Oktakit::Forbidden when 404 then Oktakit::NotFound when 405 then Oktakit::MethodNotAllowed when 406 then Oktakit::NotAcceptable when 409 then Oktakit::Conflict when 415 then Oktakit::UnsupportedMediaType when 422 then Oktakit::UnprocessableEntity when 400..499 then Oktakit::ClientError when 500 then Oktakit::InternalServerError when 501 then Oktakit::NotImplemented when 502 then Oktakit::BadGateway when 503 then Oktakit::ServiceUnavailable when 500..599 then Oktakit::ServerError end end |
.from_response(response) ⇒ Oktakit::Error
Returns the appropriate Oktakit::Error subclass based on status and response message
9 10 11 12 13 14 |
# File 'lib/oktakit/error.rb', line 9 def self.from_response(response) status = response[:status].to_i if (klass = error(status)) klass.new(response) end end |
Instance Method Details
#data ⇒ Object
51 52 53 |
# File 'lib/oktakit/error.rb', line 51 def data @data ||= parse_data end |
#errors ⇒ Array<Hash>
Array of validation errors
43 44 45 46 47 48 49 |
# File 'lib/oktakit/error.rb', line 43 def errors if data&.is_a?(Hash) data[:errors] || [] else [] end end |