Exception: Virtuatable::API::Errors::Base

Inherits:
StandardError
  • Object
show all
Defined in:
lib/virtuatable/api/errors/base.rb

Overview

Standard class parent to all specialized http errors.

Author:

Direct Known Subclasses

BadRequest, Forbidden, NotFound

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field:, error:, status:) ⇒ Base

Returns a new instance of Base.



22
23
24
25
26
# File 'lib/virtuatable/api/errors/base.rb', line 22

def initialize(field:, error:, status:)
  @field = field.to_s
  @error = error
  @status = status
end

Instance Attribute Details

#actionString

Returns the name of the action the user was trying to perform on the model (often crate or update).

Returns:

  • (String)

    the name of the action the user was trying to perform on the model (often crate or update).



14
15
16
# File 'lib/virtuatable/api/errors/base.rb', line 14

def action
  @action
end

#errorString

Returns the label of the error returned by the model.

Returns:

  • (String)

    the label of the error returned by the model.



17
18
19
# File 'lib/virtuatable/api/errors/base.rb', line 17

def error
  @error
end

#fieldString, Symbol

Returns the name of the field in error in the model.

Returns:

  • (String, Symbol)

    the name of the field in error in the model.



11
12
13
# File 'lib/virtuatable/api/errors/base.rb', line 11

def field
  @field
end

#statusInteger

Returns the HTTP status code as a number (eg: 400, 422 or 500).

Returns:

  • (Integer)

    the HTTP status code as a number (eg: 400, 422 or 500)



20
21
22
# File 'lib/virtuatable/api/errors/base.rb', line 20

def status
  @status
end

Instance Method Details

#messageObject



28
29
30
# File 'lib/virtuatable/api/errors/base.rb', line 28

def message
  "#{field}.#{error}"
end