Exception: JsonErrors::BasicError
- Inherits:
-
StandardError
- Object
- StandardError
- JsonErrors::BasicError
show all
- Defined in:
- lib/json_errors/error/basic_error.rb
Overview
Main error class to be rescued from
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(msg, name) ⇒ 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
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(_options = nil)
{
code: code,
message: to_s
}.to_json
end
|