aserafin / grape_logging

Request logging for Grape!
MIT License
147 stars 76 forks source link

wrong status code 500 logged #45

Open thedarkside opened 6 years ago

thedarkside commented 6 years ago

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 commented 6 years ago

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?

aserafin commented 6 years ago

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

thedarkside commented 3 years ago

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