lodestar
lodestar copied to clipboard
API error responses are not spec compliant
API error responses are not compliant with the Beacon API spec
eg.
Expected
curl http://localhost:9596/eth/v1/beacon/states/current/root | jq
{
"code": 400,
"message": "Invalid state ID: current"
}
Actual
{
"statusCode": 400,
"error": "Bad Request",
"message": "Invalid block id 'current'"
}
Expected
curl "http://localhost:9596/eth/v1/beacon/pool/attestations?slot=current&committee_index=123" | jq
{
"code": 400,
"message": "Invalid slot: current"
}
Actual
[
{
"instancePath": "/slot",
"schemaPath": "#/properties/slot/type",
"keyword": "type",
"params": {
"type": "integer"
},
"message": "must be integer"
}
]
Expected
curl http://localhost:9596/eth/v1/beacon/headers/123 | jq
{
"code": 404,
"message": "Block not found"
}
Actual
{
"statusCode": 404,
"error": "Not Found",
"message": "No block found for id '123'"
}
From https://github.com/ChainSafe/lodestar/issues/5710#issuecomment-1860240826
From my preliminary investigations:
-
statusCode
anderror
are added by fastify. We should be able to modify it in the handler. MapstatusCode
tocode
and ignoreerror
entirely. - data validation errors are formatted and returned by the
if (err.validation) {}
block inserver.setErrorHandler
. Just like above we can easily change the format to what we prefer.
I'll take this up after #6293 if the issue is still unassigned.
For ajv schema errors, we can just override schemaErrorFormatter