grape_logging icon indicating copy to clipboard operation
grape_logging copied to clipboard

wrong status code 500 logged

Open thedarkside opened this issue 7 years ago • 3 comments

I am using the newest gem versions. It looks like the logger is executed before the rescue_from which sets the statuscode.

  logger.formatter = GrapeLogging::Formatters::Default.new
  use GrapeLogging::Middleware::RequestLogger, logger: logger, include: [ GrapeLogging::Loggers::Response.new,
                                                                               GrapeLogging::Loggers::FilterParameters.new,
                                                                               GrapeLogging::Loggers::ClientEnv.new,
                                                                               GrapeLogging::Loggers::RequestHeaders.new ]

  rescue_from WineBouncer::Errors::OAuthUnauthorizedError do |e|
    error! e, 401
  end

thedarkside avatar Jan 29 '18 11:01 thedarkside

Simple fix:

  insert_before Grape::Middleware::Error, GrapeLogging::Middleware::RequestLogger, logger: logger, include: [ GrapeLogging::Loggers::Response.new,
                                                                               GrapeLogging::Loggers::FilterParameters.new,
                                                                               GrapeLogging::Loggers::ClientEnv.new,
                                                                               GrapeLogging::Loggers::RequestHeaders.new ]

Instead of use ... just insert_before Grape::Middleware::Error,... and the exceptions hit the logger after the rescue_from handlers. Now the logger logs the right status code.

I am using grape v1.0.2

Maybe update the readme?

thedarkside avatar Jan 29 '18 23:01 thedarkside

@thedarkside thanks for the report! could you please create PR for the readme?

aserafin avatar Feb 01 '18 13:02 aserafin

Seems already partially done with https://github.com/aserafin/grape_logging/pull/74

thedarkside avatar Oct 08 '21 19:10 thedarkside