Class: JSONAPIErrors::HashRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonapi_errors/hash_renderer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception) ⇒ HashRenderer

Returns a new instance of HashRenderer.



5
6
7
# File 'lib/jsonapi_errors/hash_renderer.rb', line 5

def initialize(exception)
  @exception = exception
end

Instance Attribute Details

#exceptionObject (readonly)

Returns the value of attribute exception.



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

def exception
  @exception
end

Instance Method Details

#renderObject



9
10
11
12
13
# File 'lib/jsonapi_errors/hash_renderer.rb', line 9

def render
  return unhandled_exception_error unless data = JSONAPIErrors::Configuration.matches.fetch(@exception.class.to_s, false)
  data.reverse_merge!({title: @exception.class.to_s, detail: @exception.message, status: "500"})
  {errors: [data]}
end