Exception: ServiceError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/service_error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, error_obj = {}) ⇒ ServiceError



15
16
17
18
19
20
# File 'lib/service_error.rb', line 15

def initialize(key, error_obj={})
  @key = key
  error_message = error_obj.delete(:error_message) || key
  @error_obj = error_obj
  super(error_message)
end

Instance Attribute Details

#error_objObject (readonly)

Returns the value of attribute error_obj.



3
4
5
# File 'lib/service_error.rb', line 3

def error_obj
  @error_obj
end

#keyObject (readonly)

Returns the value of attribute key.



2
3
4
# File 'lib/service_error.rb', line 2

def key
  @key
end

Class Method Details

.generate_from_exception(exception, append_info = {}) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/service_error.rb', line 6

def generate_from_exception(exception, append_info={})
  error_obj = {error_message: "#{exception.class.name}: #{exception.message}"}
  error_obj.merge!(append_info)
  service_err = new(:internal_error, error_obj)
  service_err.set_backtrace(exception.backtrace)
  service_err
end