module RemoteResource::Rescue
Methods that help with loading and naming the Base
class.
Public Instance Methods
with_error_handling(context = {}) { || ... }
click to toggle source
Public: Use the with_error_handling
method to use the error handling behavior defined in the rescue_from calls on the class. Take a block, whose body will error rescued.
Note that it is typically ‘wrong’ in Ruby to rescue Exception. In this case it is OK because we re raise the error if it is not handled. Inspired by ActiveController. rubocop:disable Lint/RescueException
Returns the last executed statement value.
# File lib/remote_resource/base/rescue.rb, line 20 def with_error_handling(context = {}) yield rescue Exception => exception rescue_with_handler(exception, context) || raise(exception) end
Private Instance Methods
rescue_with_handler(exception, context = {})
click to toggle source
Internal: Override the default ActiveSupport::Rescuable behavior to allow for additional context argument to be supplied as well. These error handlers are reused in different situations, and the context argument allows one to change the behavior depending on which situation.
# File lib/remote_resource/base/rescue.rb, line 32 def rescue_with_handler(exception, context = {}) if (handler = handler_for_rescue(exception)) case handler.arity when 2 then handler.call(exception, context) when 1 then handler.call(exception) when 0 then handler.call end true # don't rely on the return value of the handler end end