All text errors reported by the Craton REST API should be JSON encoded

Bug #1665015 reported by Jim Baker
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
craton
Fix Released
High
git-harry

Bug Description

This came up recently with a 500 server error with a misconfigured logger; this should have been intercepted in the response chain. So compare:

$ curl http://127.0.0.1:8080/v1/projects/xb9f10eca-66ac-4c27-9c13-9d01e65f96b4 -H "Content-Type: application/json" -H "X-Auth-Token: demo" -H "X-Auth-User: demo" -H "X-Auth-Project: b9f10eca66ac4c279c139d01e65f96b4"
A server error occurred. Please contact the administrator.

vs what we usually do:

$ curl http://127.0.0.1:8080/v1/hosts/1 -H "Content-Type: application/json" -H "X-Auth-Token: demo" -H "X-Auth-User: demo" -H "X-Auth-Project: b9f10eca66ac4c279c139d01e65f96b4"
{
  "message": "Not Found",
  "status": 404
}

We may want to further revisit the specific error text as well; see https://specs.openstack.org/openstack/api-wg/guidelines/errors.html, but any such work is likely to be a more expansive blueprint/spec, and is out of scope for this specific bug.

git-harry (git-harry)
Changed in craton:
assignee: nobody → git-harry (git-harry)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to craton (master)

Reviewed: https://review.openstack.org/443565
Committed: https://git.openstack.org/cgit/openstack/craton/commit/?id=cbb246111b9394d3c02843c2744a5e93c1acebd5
Submitter: Jenkins
Branch: master

commit cbb246111b9394d3c02843c2744a5e93c1acebd5
Author: git-harry <email address hidden>
Date: Thu Mar 9 09:16:51 2017 +0000

    Add http_codes decorator where missing

    This commit adds the decorator http_codes to a number of the API put
    methods so that all now use it. This ensures any exceptions generated by
    the methods return the expected status code and the response body is
    JSON encoded.

    Change-Id: Id24ef3687afe21e36adae225efdef7150b5d5318
    Partial-bug: 1665015

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to craton (master)

Fix proposed to branch: master
Review: https://review.openstack.org/447580

Changed in craton:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to craton (master)

Reviewed: https://review.openstack.org/447580
Committed: https://git.openstack.org/cgit/openstack/craton/commit/?id=533492b4d36ded28fe9aadd1c51c2260cccafedb
Submitter: Jenkins
Branch: master

commit 533492b4d36ded28fe9aadd1c51c2260cccafedb
Author: git-harry <email address hidden>
Date: Mon Mar 20 16:08:49 2017 +0000

    Ensure JSON responses result from failure

    Responses generated from failure should be JSON formatted.

    flask_restful.Api is subclassed to control the format of all error
    responses generated by the API Flask app.

    The API middleware is modified to use the same error response function
    given that it is not part of the Flask app for the API. Any Response
    object created by the middleware has been converted to an exception to
    ensure that all error responses are generated using the same code.

    The use of abort has been replaced with raising exceptions, this further
    consolidates the error response mechanism.

    response_filter has been modified so that it always expects to receive a
    response tuple now that http_codes is no longer there to return a
    response object.

    The error filters in schemas.py have been removed. These were not used
    by the existing code.

    Closes-bug: 1665015

    Change-Id: I2be40e9493f313b3fe0173c34d371659039c1bae

Changed in craton:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.