-
Notifications
You must be signed in to change notification settings - Fork 33
Description
Hi. While exploring the grape-middleware-logger
logs I discovered that all requests with errors that are preprocessed with rescue_from
are marked with 500 response code:
# api.rb
class API < Grape::API
use Grape::Middleware::Logger
format :json
include ExceptionHandler
mount V1::Base
end
# exception_handler.rb
module ExceptionHandler
extend ActiveSupport::Concern
included do
rescue_from ActiveRecord::RecordNotFound do
error!({ error: :not_found }, 404)
end
# ... other :rescue_from ...
end
end
Log:
I, [2016-09-14T14:53:49.896641 #27381] INFO -- : [f4b3b020-ef4b-44ea-9228-fc58d35c1687] ActiveRecord::RecordNotFound (Couldn't find User with 'id'=1010):
I looked at the source code of the gem and added some trace to the code. And what am I found is that rescue_from
are invoked after grape-middleware-logger
methods such as after_exception
and after_failure
. So the real status code (and maybe some extra info) does not fall into the log, only 500. I think that is a wrong behaviour.
Gemfile.lock
grape (0.17.0)
grape-middleware-logger (1.7.0)
What do you think about that, @ridiculous?