def rescue_from(*args, &block)
if args.last.is_a?(Proc)
handler = args.pop
elsif block_given?
handler = block
end
options = args.extract_options!
if block_given? && options.key?(:with)
raise ArgumentError, 'both :with option and block cannot be passed'
end
handler ||= extract_with(options)
if args.include?(:all)
namespace_inheritable(:rescue_all, true)
namespace_inheritable :all_rescue_handler, handler
elsif args.include?(:grape_exceptions)
namespace_inheritable(:rescue_all, true)
namespace_inheritable(:rescue_grape_exceptions, true)
else
handler_type =
case options[:rescue_subclasses]
when nil, true
:rescue_handlers
else
:base_only_rescue_handlers
end
namespace_reverse_stackable handler_type, Hash[args.map { |arg| [arg, handler] }]
end
namespace_stackable(:rescue_options, options)
end