Exception: Oktakit::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/oktakit/error.rb

Overview

Custom error class for rescuing from all Okta errors

Direct Known Subclasses

ClientError, ServerError

Class Method Summary collapse

Instance Method Summary collapse

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(build_error_message)
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

Parameters:

  • response (Hash)

    HTTP response

Returns:



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

#dataObject



51
52
53
# File 'lib/oktakit/error.rb', line 51

def data
  @data ||= parse_data
end

#errorsArray<Hash>

Array of validation errors

Returns:

  • (Array<Hash>)

    Error info



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