Class: Noise::ExceptionRenderer
- Inherits:
-
Struct
- Object
- Struct
- Noise::ExceptionRenderer
- Defined in:
- lib/noise/exception_renderer.rb
Overview
Determines how to render exception
Instance Attribute Summary collapse
-
#env ⇒ Object
Returns the value of attribute env.
Instance Method Summary collapse
- #error ⇒ StandardError
-
#error_id ⇒ String
Error identifier, UUID.
- #error_serializer ⇒ Object
-
#render(responder) ⇒ String
Error representation.
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env
39 40 41 |
# File 'lib/noise/exception_renderer.rb', line 39 def env @env end |
Instance Method Details
#error ⇒ StandardError
58 59 60 |
# File 'lib/noise/exception_renderer.rb', line 58 def error env['action_dispatch.exception'] end |
#error_id ⇒ String
Returns error identifier, UUID.
63 64 65 |
# File 'lib/noise/exception_renderer.rb', line 63 def error_id env['action_dispatch.request_id'] end |
#error_serializer ⇒ Object
53 54 55 |
# File 'lib/noise/exception_renderer.rb', line 53 def error_serializer error.is_a?(PublicError) ? PublicErrorSerializer : ErrorSerializer end |
#render(responder) ⇒ String
Returns error representation.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/noise/exception_renderer.rb', line 42 def render(responder) ActiveModelSerializers::SerializableResource.new( Array(error), each_serializer: error_serializer, adapter: :json, root: 'errors', meta: { 'status' => responder.status_code }.merge(error.try(:meta_hash) || {}), scope: { http_status: responder.status_code, id: error_id }, ).as_json.to_json end |