Module: JsonApiToolbox::RenderizableExceptions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/renderizable_exceptions.rb
Instance Method Summary collapse
- #build_jsonapi(exception) ⇒ Object
- #code(exception) ⇒ Object
- #model_errors_code(error) ⇒ Object
- #puts_build_log_error(error) ⇒ Object
- #render_any_exception(exception) ⇒ Object
Instance Method Details
#build_jsonapi(exception) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/renderizable_exceptions.rb', line 19 def build_jsonapi(exception) { jsonapi_errors: { title: exception.class.to_s, detail: exception., status: 500, code: code(exception), source: {} }, jsonapi_class: { class: { Hash: JsonApiToolbox::Serializables::SerializableException } } } end |
#code(exception) ⇒ Object
35 36 37 38 39 |
# File 'lib/renderizable_exceptions.rb', line 35 def code(exception) model_errors_code(exception) || exception.try(:code) || 'default_error' end |
#model_errors_code(error) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/renderizable_exceptions.rb', line 41 def model_errors_code(error) detail_error = error.try(:detail) detail_error.try(:map, &:flatten).try(:map) do |item| [item[0], item[1]['error']].join('_error_') end end |
#puts_build_log_error(error) ⇒ Object
31 32 33 |
# File 'lib/renderizable_exceptions.rb', line 31 def puts_build_log_error(error) puts messages: error.try(:message), trace: error.try(:backtrace) end |
#render_any_exception(exception) ⇒ Object
13 14 15 16 17 |
# File 'lib/renderizable_exceptions.rb', line 13 def render_any_exception(exception) puts_build_log_error(exception) render build_jsonapi(exception) end |