Class: Crystal::Processors::ControllerErrorHandling
- Inherits:
-
Crystal::Processor
- Object
- Crystal::Processor
- Crystal::Processors::ControllerErrorHandling
- Defined in:
- lib/crystal/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 = crystal.config.send "#{crystal.config.environment!}_error_template", nil if tname and Template.exist?(tname, :format => format) data = Template.render(tname, :format => format, :locals => {:error => e} ) else e. end }
Instance Attribute Summary collapse
-
#result_variable ⇒ Object
Returns the value of attribute result_variable.
Attributes inherited from Crystal::Processor
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(next_processor, result_variable = 'content') ⇒ ControllerErrorHandling
constructor
A new instance of ControllerErrorHandling.
Methods inherited from Crystal::Processor
Constructor Details
#initialize(next_processor, result_variable = 'content') ⇒ ControllerErrorHandling
Returns a new instance of ControllerErrorHandling.
6 7 8 9 10 |
# File 'lib/crystal/controller/processors/controller_error_handling.rb', line 6 def initialize next_processor, result_variable = 'content' result_variable.must_be.present super(next_processor) @result_variable = result_variable end |
Instance Attribute Details
#result_variable ⇒ Object
Returns the value of attribute result_variable.
4 5 6 |
# File 'lib/crystal/controller/processors/controller_error_handling.rb', line 4 def result_variable @result_variable end |
Instance Method Details
#call ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/crystal/controller/processors/controller_error_handling.rb', line 12 def call begin next_processor.call rescue StandardError => e if config.test? raise e elsif config.production? error_shown_to_user = StandardError.new "Internal error!" error_shown_to_user.set_backtrace [] else error_shown_to_user = e end format = workspace.params.format handler = SPECIAL_ERROR_HANDLERS[format] || DEFAULT_ERROR_HANDLER workspace[result_variable] = handler.call error_shown_to_user, format logger.error e logger.info "\n" end end |