class BusinessError::Error

Attributes

code[RW]
format[RW]
http_status[RW]
msg[RW]
name[RW]

Public Class Methods

new(name, msg, code, http_status = Config.default_http_status, format = Config.default_format) click to toggle source
# 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

Public Instance Methods

format!(template, **addition_content) click to toggle source
# 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
Also aliased as: render!
info() click to toggle source
# File lib/business_error/error.rb, line 15
def info
  @info ||= { code: @code, msg: @msg, http: @http_status }
end
message() click to toggle source
# File lib/business_error/error.rb, line 36
def message; info.to_s end
render!(template, **addition_content)
Alias for: format!
throw!() click to toggle source
# File lib/business_error/error.rb, line 19
def throw!
  format ? format!(format) : (raise self)
end
with!(**addition_content) click to toggle source
# File lib/business_error/error.rb, line 31
def with!(**addition_content)
  info.merge!(data: addition_content)
  raise self
end