Page MenuHomeSoftware Heritage

api/graph: Fix error responses for invalid request Accept header
ClosedPublic

Authored by anlambert on Oct 25 2021, 1:47 PM.

Details

Summary

When setting an unsupported value for the request Accept header when
querying the /api/1/graph/ endpoint, an error was raised as the Django
DRF response does not have the accepted_media_type attribute set in
that case, leading to a 500 HTTP status code.

So ensure a proper JSON error response will be generated with the
406 HTTP status code when submitting such requests.

Related sentry issue

Diff Detail

Repository
rDWAPPS Web applications
Branch
api-graph-fix-invalid-accept-header-response
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 24680
Build 38515: Phabricator diff pipeline on jenkinsJenkins console · Jenkins
Build 38514: arc lint + arc unit

Event Timeline

Build is green

Patch application report for D6546 (id=23796)

Rebasing onto 1edcf35c48...

Current branch diff-target is up to date.
Changes applied before test
commit eb1d40198a082bbd022795cae09cfd2ef47ca30a
Author: Antoine Lambert <anlambert@softwareheritage.org>
Date:   Mon Oct 25 13:40:54 2021 +0200

    api/graph: Fix error responses for invalid request Accept header
    
    When setting an unsupported value for the request Accept header when
    querying the /api/1/graph/ endpoint, an error was raised as the Django
    DRF response does not have the accepted_media_type attribute set in
    that case, leading to a 500 HTTP status code.
    
    So ensure a proper JSON error response will be generated with the
    406 HTTP status code when submitting such requests.

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1210/ for more details.

This revision is now accepted and ready to land.Oct 25 2021, 3:12 PM