mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-15 08:50:45 -07:00
Allow the exception handler to convert exceptions to hide error messages.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user