Commit 6b98033d authored by Stan Hu's avatar Stan Hu

Fix api_json.log not always reporting the right HTTP status code

As described in https://github.com/aserafin/grape_logging/issues/45, if
a Grape error is caught by the handlers and a different return code
is returned, then the api_json.log would have a 500 error code
instead of the right value. Inserting the GrapeLogging middleware
after the Grape middleware fixes this problem.

Seen in https://gitlab.com/gitlab-com/infrastructure/issues/4249
parent 4609a126
---
title: Fix api_json.log not always reporting the right HTTP status code
merge_request:
author:
type: fixed
...@@ -8,14 +8,15 @@ module API ...@@ -8,14 +8,15 @@ module API
PROJECT_ENDPOINT_REQUIREMENTS = { id: NO_SLASH_URL_PART_REGEX }.freeze PROJECT_ENDPOINT_REQUIREMENTS = { id: NO_SLASH_URL_PART_REGEX }.freeze
COMMIT_ENDPOINT_REQUIREMENTS = PROJECT_ENDPOINT_REQUIREMENTS.merge(sha: NO_SLASH_URL_PART_REGEX).freeze COMMIT_ENDPOINT_REQUIREMENTS = PROJECT_ENDPOINT_REQUIREMENTS.merge(sha: NO_SLASH_URL_PART_REGEX).freeze
use GrapeLogging::Middleware::RequestLogger, insert_before Grape::Middleware::Error,
logger: Logger.new(LOG_FILENAME), GrapeLogging::Middleware::RequestLogger,
formatter: Gitlab::GrapeLogging::Formatters::LogrageWithTimestamp.new, logger: Logger.new(LOG_FILENAME),
include: [ formatter: Gitlab::GrapeLogging::Formatters::LogrageWithTimestamp.new,
GrapeLogging::Loggers::FilterParameters.new, include: [
GrapeLogging::Loggers::ClientEnv.new, GrapeLogging::Loggers::FilterParameters.new,
Gitlab::GrapeLogging::Loggers::UserLogger.new GrapeLogging::Loggers::ClientEnv.new,
] Gitlab::GrapeLogging::Loggers::UserLogger.new
]
allow_access_with_scope :api allow_access_with_scope :api
prefix :api prefix :api
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment