Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API error responses are not spec compliant #6480

Open
nflaig opened this issue Feb 25, 2024 · 2 comments
Open

API error responses are not spec compliant #6480

nflaig opened this issue Feb 25, 2024 · 2 comments
Labels
good first issue Issues that are suitable for first-time contributors. help-wanted The author indicates that additional help is wanted. scope-interop Issues that fix interop issues between Lodestar and CL, EL or tooling.

Comments

@nflaig
Copy link
Member

nflaig commented Feb 25, 2024

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 #5710 (comment)

@nflaig nflaig added good first issue Issues that are suitable for first-time contributors. help-wanted The author indicates that additional help is wanted. scope-interop Issues that fix interop issues between Lodestar and CL, EL or tooling. labels Feb 25, 2024
@har777
Copy link
Contributor

har777 commented Feb 26, 2024

From my preliminary investigations:

  1. statusCode and error are added by fastify. We should be able to modify it in the handler. Map statusCode to code and ignore error entirely.
  2. data validation errors are formatted and returned by the if (err.validation) {} block in server.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.

@nflaig
Copy link
Member Author

nflaig commented Mar 14, 2024

For ajv schema errors, we can just override schemaErrorFormatter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issues that are suitable for first-time contributors. help-wanted The author indicates that additional help is wanted. scope-interop Issues that fix interop issues between Lodestar and CL, EL or tooling.
Projects
None yet
Development

No branches or pull requests

2 participants