Created
April 13, 2021 17:47
-
-
Save BlakeWilliams/f17bd24ac9234638c03ac39dde6e9271 to your computer and use it in GitHub Desktop.
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
module Rescuable | |
extend ActiveSupport::Concern | |
class_methods do | |
def rescue_with_empty_content? | |
defined?(@rescue_with_empty_content) && @rescue_with_empty_content | |
end | |
def rescue_with_empty_content! | |
@rescue_with_empty_content = true | |
end | |
end | |
def render_in(*) | |
super | |
rescue StandardError => e | |
raise unless self.class.rescue_with_empty_content? | |
raise unless Rails.env.production? | |
respond_to?(:on_error, true) && on_error(e) | |
"" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment