Log server responses of API bad requests in api_json.log
The API helper render_api_error!
previously would log a 400 error with
no details in api_json.log
, which made it difficult to debug problems
in production. To fix this, we need to:
- Store the intended status code in the request environment. grape-logging doesn't pass this along to the loggers: https://github.com/aserafin/grape_logging/issues/71
- In the logger, check the code. If it is 400, attach an
api_error
field that contains the response from the server.
For example:
{
"time": "2020-04-17T23:59:09.024Z",
"severity": "INFO",
<snip>
"route": "/api/:version/jobs/:id/artifacts",
"api_error": [
"{\"message\":\"Validation failed: Invalid file format with specified file type\"}"
],
"correlation_id": "c97d6253-1f92-44d8-91de-b27c1c6d1509"
}
Closes #214879 (closed)
Edited by Stan Hu