Class: ControllerErrorHandling
- Inherits:
-
Rad::Conveyors::Processor
- Object
- Rad::Conveyors::Processor
- ControllerErrorHandling
- Defined in:
- lib/rad/controller/processors/controller_error_handling.rb
Constant Summary collapse
- SPECIAL_ERROR_HANDLERS =
{ 'json' => lambda{|e, format| {error: e.}.to_json } }
- DEFAULT_ERROR_HANDLER =
lambda{|e, format| tname = rad.controller.send("#{rad.mode}_error_template") if tname and rad.template.exist?(tname, format: format, exact_format: true) data = rad.template.render(tname, format: format, locals: {error: e} ) else e. end }
Instance Attribute Summary
Attributes inherited from Rad::Conveyors::Processor
Instance Method Summary collapse
Methods inherited from Rad::Conveyors::Processor
Constructor Details
This class inherits a constructor from Rad::Conveyors::Processor
Instance Method Details
#call ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rad/controller/processors/controller_error_handling.rb', line 4 def call workspace.response.must_be.defined begin next_processor.call rescue StandardError => e if rad.test? # e.set_backtrace e.backtrace.sfilter(Exception.filters) raise e elsif rad.production? error_shown_to_user = StandardError.new "Internal error!" error_shown_to_user.set_backtrace [] else error_shown_to_user = e end workspace.response.clear if workspace.response format = workspace.params.format handler = SPECIAL_ERROR_HANDLERS[format] || DEFAULT_ERROR_HANDLER workspace.content = handler.call error_shown_to_user, format logger.error e logger.info "\n" end end |