Exception: BusinessError::Error
- Inherits:
-
StandardError
- Object
- StandardError
- BusinessError::Error
- Defined in:
- lib/business_error/error.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#format ⇒ Object
Returns the value of attribute format.
-
#http_status ⇒ Object
Returns the value of attribute http_status.
-
#msg ⇒ Object
Returns the value of attribute msg.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #format!(template, **addition_content) ⇒ Object (also: #render!)
- #info ⇒ Object
-
#initialize(name, msg, code, http_status = Config.default_http_status, format = Config.default_format) ⇒ Error
constructor
A new instance of Error.
- #message ⇒ Object
- #throw! ⇒ Object
- #with!(**addition_content) ⇒ Object
Constructor Details
#initialize(name, msg, code, http_status = Config.default_http_status, format = Config.default_format) ⇒ Error
Returns a new instance of Error.
9 10 11 12 13 |
# File 'lib/business_error/error.rb', line 9 def initialize(name, msg, code, http_status = Config.default_http_status, format = Config.default_format) msg = name.to_s.humanize if msg.blank? @name, @msg, @code, @http_status = name, msg, code, http_status self.format = format end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
7 8 9 |
# File 'lib/business_error/error.rb', line 7 def code @code end |
#format ⇒ Object
Returns the value of attribute format.
7 8 9 |
# File 'lib/business_error/error.rb', line 7 def format @format end |
#http_status ⇒ Object
Returns the value of attribute http_status.
7 8 9 |
# File 'lib/business_error/error.rb', line 7 def http_status @http_status end |
#msg ⇒ Object
Returns the value of attribute msg.
7 8 9 |
# File 'lib/business_error/error.rb', line 7 def msg @msg end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/business_error/error.rb', line 7 def name @name end |
Instance Method Details
#format!(template, **addition_content) ⇒ Object Also known as: render!
23 24 25 26 27 |
# File 'lib/business_error/error.rb', line 23 def format!(template, **addition_content) content = Config.formats[template].each_with_index.map { |k, i| [k, info.values[i]] }.to_h @info = { only: content.merge(addition_content) } raise self end |
#info ⇒ Object
15 16 17 |
# File 'lib/business_error/error.rb', line 15 def info @info ||= { code: @code, msg: @msg, http: @http_status } end |
#message ⇒ Object
36 |
# File 'lib/business_error/error.rb', line 36 def ; info.to_s end |
#throw! ⇒ Object
19 20 21 |
# File 'lib/business_error/error.rb', line 19 def throw! format ? format!(format) : (raise self) end |
#with!(**addition_content) ⇒ Object
31 32 33 34 |
# File 'lib/business_error/error.rb', line 31 def with!(**addition_content) info.merge!(data: addition_content) raise self end |