Skip to content

Error Middleware Rescuable Doesn't Handle Inheritance #542

@xevix

Description

@xevix

Suppose you have an error hierarchy as below:

module APIErrors
  class ParentError < StandardError; end
  class Child < ParentError; end
end

In the API file, suppose you then attempt to rescue from all errors in a standard way:

rescue_from APIErrors::ParentError do |e|
  Rack::Response.new({
    error: "#{e.class} error",
    message: e.message
  }.to_json, e.status)
end

Now suppose a Child error is raised:

raise APIErrors::Child, "Rescue me, please!"

Because the middleware checks only for a list of classes in rescuable?(klass) and the Child class is not included in the list, it will never rescue this.

Is there a way to have all ParentError-derivative classes be rescued?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions