Exception: Api::Exception
- Inherits:
-
StandardError
- Object
- StandardError
- Api::Exception
- Defined in:
- lib/api/exception.rb
Instance Attribute Summary collapse
-
#messages ⇒ Object
Returns the value of attribute messages.
Class Method Summary collapse
Instance Method Summary collapse
- #full_messages ⇒ Object
-
#initialize(error_constant, messages = nil) ⇒ Exception
constructor
A new instance of Exception.
- #status_code ⇒ Object
Constructor Details
#initialize(error_constant, messages = nil) ⇒ Exception
Returns a new instance of Exception.
10 11 12 13 14 15 |
# File 'lib/api/exception.rb', line 10 def initialize(error_constant, = nil) @error_constant = error_constant @messages = { @error_constant[:key].to_s => [ || @error_constant[:message]] } end |
Instance Attribute Details
#messages ⇒ Object
Returns the value of attribute messages.
8 9 10 |
# File 'lib/api/exception.rb', line 8 def @messages end |
Class Method Details
.error_constants ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/api/exception.rb', line 26 def error_constants { INTERNAL_SERVER_ERROR: { message: t(:internal_server_error), key: :internal_server_error, status_code: :internal_server_error }, RECORD_NOT_FOUND: { message: t(:record_not_found), key: :record_not_found, status_code: :not_found }, RECORD_INVALID: { message: t(:record_invalid), key: :record_invalid, status_code: :unprocessable_entity }, RECORD_NOT_DESTROYED: { message: t(:record_not_destroyed), key: :record_not_destroyed, status_code: :forbidden }, FORBIDDEN_RESOURCE: { message: t(:forbidden_resource), key: :forbidden_resource, status_code: :forbidden }, UNAUTHORIZED_ACCESS: { message: t(:unauthorized_access), key: :unauthorized_access, status_code: :unauthorized } } end |
Instance Method Details
#full_messages ⇒ Object
17 18 19 |
# File 'lib/api/exception.rb', line 17 def @messages.values.flatten end |
#status_code ⇒ Object
21 22 23 |
# File 'lib/api/exception.rb', line 21 def status_code @error_constant[:status_code] end |