Skip to content

Unify HTTP 400 responses #1595

@fridex

Description

@fridex

Describe the bug

User API responds with 400 HTTP status codes for invalid requests. These requests can be invalid on multiple layers though. They can be invalid based on checks that are done in implemented endpoint handlers but also based on schema validation. The schema validation issue reports are handled by connexion and differ from the ones that are implemented by us in the Python code. They do not conform to HTTP 400 schema that is declared on Python endpoints.

To Reproduce
Steps to reproduce the behavior:

  1. As an example, use a CLI tool to interact with API and ask for results on an endpoint but do not provide required input:
curl -X 'GET' \
  'http://stage.thoth-station.ninja/api/v1/python/package/version/metadata?name=flask&version=0.12&index=https%3A%2F%2Fpypi.org%2Fsimple&os_version=8&python_version=3.8' \
  -H 'accept: application/json'
{
  "detail": "Missing query parameter 'os_name'",
  "status": 400,
  "title": "Bad Request",
  "type": "about:blank"
}
  1. See the response is not conforming to the OpenAPI spec

Expected behavior

The response should be conforming to the OpenAPI spec.

Additional context

I've tried to register a custom flask for 400 or providing a custom connexion validator. None of these worked though - I did not invest much time into this, but it might be nice to have.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/user-apiIssues or PRs related to the User APIgood first issueDenotes an issue ready for a new contributor, according to the "help wanted" guidelines.kind/bugCategorizes issue or PR as related to a bug.priority/backlogHigher priority than priority/awaiting-more-evidence.sig/user-experienceIssues or PRs related to the User Experience of our Services, Tools, and Libraries.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

    Type

    No type

    Projects

    Status

    📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions