Last active
August 29, 2015 13:56
-
-
Save amiel/9126937 to your computer and use it in GitHub Desktop.
Ignoring stupid errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SMRT_ERRORS = [ServiceClaimsIsATeapot] | |
def ignore_stupid_errors(error_block = ->(*){}) | |
yield | |
rescue *SMRT_ERRORS => e | |
error_block.call e | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeClass | |
def do_something | |
ignore_stupid_errors do | |
check_the_teapot | |
end | |
end | |
def with_handle_error | |
ignore_stupid_errors(method(:error_handler)) do | |
check_the_teapot | |
end | |
end | |
def error_handler(error) | |
puts "Oops #{error.inspect}" | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment