Class: Devise::Api::Responses::ErrorResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/devise/api/responses/error_response.rb

Constant Summary collapse

ERROR_TYPES =
%i[
  invalid_token
  expired_token
  expired_refresh_token
  revoked_token
  refresh_token_disabled
  sign_up_disabled
  invalid_refresh_token
  invalid_email
  invalid_resource_owner
  resource_owner_create_error
  devise_api_token_create_error
  devise_api_token_revoke_error
  invalid_authentication
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, error:, record: nil, resource_class: nil) ⇒ ErrorResponse

Returns a new instance of ErrorResponse.



33
34
35
36
37
38
# File 'lib/devise/api/responses/error_response.rb', line 33

def initialize(request, error:, record: nil, resource_class: nil)
  @request = request
  @error = error
  @record = record
  @resource_class = resource_class
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



7
8
9
# File 'lib/devise/api/responses/error_response.rb', line 7

def error
  @error
end

#recordObject (readonly)

Returns the value of attribute record.



7
8
9
# File 'lib/devise/api/responses/error_response.rb', line 7

def record
  @record
end

#requestObject (readonly)

Returns the value of attribute request.



7
8
9
# File 'lib/devise/api/responses/error_response.rb', line 7

def request
  @request
end

#resource_classObject (readonly)

Returns the value of attribute resource_class.



7
8
9
# File 'lib/devise/api/responses/error_response.rb', line 7

def resource_class
  @resource_class
end

Instance Method Details

#bodyObject



40
41
42
43
44
45
46
47
# File 'lib/devise/api/responses/error_response.rb', line 40

def body
  {
    error: error,
    error_description: error_description,
    lockable: devise_lockable_info,
    confirmable: devise_confirmable_info
  }.compact
end

#statusObject



49
50
51
52
53
54
# File 'lib/devise/api/responses/error_response.rb', line 49

def status
  return :unauthorized if unauthorized_status?
  return :bad_request if bad_request_status?

  :unprocessable_entity
end