aboutcode-org / purldb

Tools to create and expose a database of purls (Package URLs). This project is sponsored by NLnet project https://nlnet.nl/project/vulnerabilitydatabase/ and nexB for https://www.aboutcode.org/ Chat is at https://gitter.im/aboutcode-org/discuss
https://purldb.readthedocs.io/
35 stars 23 forks source link

Collect API endpoint response status code #505

Closed tdruez closed 4 months ago

tdruez commented 4 months ago

This endpoint returns a 200 status code on error.

For example: /api/collect/?purl=pkg:npm/foo@1.0

HTTP 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "status": "error(s) occurred when fetching metadata for pkg:npm/foo@1.0: Package does not exist on npmjs: pkg:npm/foo@1.0"
}

We should have an appropriate status code to make things easier on the consumer side.

By the way, calling /api/collect/ with a purl return a proper 400 status code:

HTTP 400 Bad Request
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "errors": {
        "purl": [
            "This field is required."
        ]
    }
}