Exception: JsonErrors::BasicError
- Inherits:
-
StandardError
- Object
- StandardError
- JsonErrors::BasicError
- Defined in:
- lib/json_errors/error/basic_error.rb
Overview
Main error class to be rescued from
Direct Known Subclasses
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
Class Method Summary collapse
Instance Method Summary collapse
- #http_status ⇒ Object
-
#initialize(msg, name) ⇒ BasicError
constructor
A new instance of BasicError.
- #to_json(_options = nil) ⇒ Object
Constructor Details
#initialize(msg, name) ⇒ BasicError
Returns a new instance of BasicError.
8 9 10 11 12 13 14 |
# File 'lib/json_errors/error/basic_error.rb', line 8 def initialize(msg, name) raise 'Wrong name' unless name.in?(codes.keys) @code = codes[name][:code] @name = name super(msg) end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/json_errors/error/basic_error.rb', line 6 def code @code end |
Class Method Details
.codes ⇒ Object
16 17 18 |
# File 'lib/json_errors/error/basic_error.rb', line 16 def self.codes JsonErrors.config.custom_codes end |
Instance Method Details
#http_status ⇒ Object
27 28 29 |
# File 'lib/json_errors/error/basic_error.rb', line 27 def http_status codes[name][:http_status] end |
#to_json(_options = nil) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/json_errors/error/basic_error.rb', line 20 def to_json( = nil) { code: code, message: to_s }.to_json end |