In Grape if you use the error! method it will throw an error and never call the Grape::Endpoint "after" callback.
I'd like the app to call an after hook when error! has been called.
I've added this piece of middleware to make this happen.
class AfterFailure < Grape::Middleware::Base
def call!(env)
@env = env
before
error = catch (:error) do
@app_response = @app.call(@env)
return after || @app_response
end
after_failure(error) || throw(:error, error)
end
def after_failure(error)
puts "After Failure"
nil
end
end
Is there a better way to accomplish this?
Thanks