mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Exception handling for humans
Ability to pass exception_handler as a block to #render and provide whatever behavior you want on handling exceptions https://github.com/Shopify/liquid/pull/254
This commit is contained in:
@@ -153,4 +153,18 @@ class TemplateTest < Test::Unit::TestCase
|
||||
end
|
||||
assert_equal 'ruby error in drop', e.message
|
||||
end
|
||||
|
||||
def test_exception_handler_doesnt_reraise_if_it_returns_false
|
||||
exception = nil
|
||||
Template.parse("{{ 1 | divided_by: 0 }}").render({}, exception_handler: ->(e) { exception = e; false })
|
||||
assert exception.is_a?(ZeroDivisionError)
|
||||
end
|
||||
|
||||
def test_exception_handler_does_reraise_if_it_returns_true
|
||||
exception = nil
|
||||
assert_raises(ZeroDivisionError) do
|
||||
Template.parse("{{ 1 | divided_by: 0 }}").render({}, exception_handler: ->(e) { exception = e; true })
|
||||
end
|
||||
assert exception.is_a?(ZeroDivisionError)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user