close
Skip to content

Change behaviors of rescue_from to not depend on mount order #1975

@wowinter13

Description

@wowinter13

Hi, found an interesting case when rescue_from :all should override outer rescue_from :error_class

class PublicApi < Grape::API
  rescue_from ActiveRecord::RecordNotFound do
    binding.pry
    error_response(status: 403)
  end
  mount AuthController
end
class AuthController < Grape::API
  rescue_from :all do 
    error_response(status: 403)
  end

  post :request do
    User.find_by!(phone: phone)
  end
end
15:  rescue_from ActiveRecord::RecordNotFound do
15:     binding.pry
16:     error_response(status: 403)
17:  end

For some reason, it seems to not working correctly. I suppose AuthController rescue_from :all to be called first.
But if we mount AuthController above rescue_from ActiveRecord::RecordNotFound it would work correctly.
So, does it look like a bug or additional info to documentation?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions