Allow the exception handler to convert exceptions to hide error messages.

This commit is contained in:
Dylan Thacker-Smith
2015-05-27 18:59:51 -04:00
parent 89c6e605f8
commit 8d5e71f856
4 changed files with 37 additions and 12 deletions
+14 -3
View File
@@ -186,10 +186,21 @@ class ErrorHandlingTest < Minitest::Test
end
end
def test_disabling_error_rendering
def test_exception_handler_with_string_result
template = Liquid::Template.parse('This is an argument error: {{ errors.argument_error }}')
template.render_errors = false
assert_equal 'This is an argument error: ', template.render('errors' => ErrorDrop.new)
output = template.render({ 'errors' => ErrorDrop.new }, exception_handler: ->(e) { '' })
assert_equal 'This is an argument error: ', output
assert_equal [ArgumentError], template.errors.map(&:class)
end
class InternalError < Liquid::Error
end
def test_exception_handler_with_exception_result
template = Liquid::Template.parse('This is a runtime error: {{ errors.runtime_error }}')
handler = ->(e) { e.is_a?(Liquid::Error) ? e : InternalError.new('internal') }
output = template.render({ 'errors' => ErrorDrop.new }, exception_handler: handler)
assert_equal 'This is a runtime error: Liquid error: internal', output
assert_equal [InternalError], template.errors.map(&:class)
end
end