lib/grape/api.rb
# Allows you to rescue certain exceptions that occur to return
# a grape error rather than raising all the way to the
# server level.
#
# @example Rescue from custom exceptions
#     class ExampleAPI < Grape::API
#       class CustomError < StandardError; end
#
#       rescue_from CustomError
#     end
#
# @overload rescue_from(*exception_classes, options = {})
#   @param [Array] exception_classes A list of classes that you want to rescue, or
#     the symbol :all to rescue from all exceptions.
#   @param [Block] block Execution block to handle the given exception.
#   @param [Hash] options Options for the rescue usage.
#   @option options [Boolean] :backtrace Include a backtrace in the rescue response.
Allows you to rescue certain exceptions that occur to return
a grape error rather than raising all the way to the
server level.
Allows you to rescue certain exceptions that occur to return a grape error rather than raising all the way to the server level .
def rescue_from(*args, &block)
        if block_given?
          args.each do |arg|
            imbue(:rescue_handlers, { arg => block })
          end
        end
        imbue(:rescue_options, args.pop) if args.last.is_a?(Hash)
        set(:rescue_all, true) and return if args.include?(:all)
        imbue(:rescued_errors, args)
      end
def rescue_from ( * args , & block ) if block_given? args . each do | arg | imbue ( :rescue_handlers , { arg => block } ) end end imbue ( :rescue_options , args . pop ) if args . last . is_a? ( Hash ) set ( :rescue_all , true ) and return if args . include? ( :all ) imbue ( :rescued_errors , args ) end
Allows you to rescue certain exceptions that occur to return
a grape error rather than raising all the way to the
server level.
Allows you to rescue certain exceptions that occur to return a grape error rather than raising all the way to the server level .
args
block
example
Rescue from custom exceptions class ExampleAPI < Grape::API class CustomError < StandardError; end rescue_from CustomError end
Rescue from custom exceptions class ExampleAPI < Grape :: API class CustomError < StandardError ; end rescue_from CustomError end
overload
rescue_from(*exception_classes, options = {}) @param [Array] exception_classes A list of classes that you want to rescue, or the symbol :all to rescue from all exceptions. @param [Block] block Execution block to handle the given exception. @param [Hash] options Options for the rescue usage. @option options [Boolean] :backtrace Include a backtrace in the rescue response.
rescue_from ( * exception_classes options = {} ) @param [ Array ] exception_classes A list of classes that you want to rescue or the symbol : all to rescue from all exceptions . @param [ Block ] block Execution block to handle the given exception . @param [ Hash ] options Options for the rescue usage . @option options [ Boolean ] : backtrace Include a backtrace in the rescue response .