commit 9b052e4c059893791dd7adc4aa32d40ac098e788
Author: Morgan Fainberg <email address hidden>
Date: Thu Oct 11 12:32:59 2018 -0700
Register exceptions with a Flask Error Handler
Exceptions are now handled in the Flask APP instead of in the
legacy webob Application code (at this point that code was living
in the URL Normalizing Middleware). All Keystone API exceptions
(derived from keystone.exception.Error) are automatically
registered on definition with the
keystone.exception.KEYSTONE_API_EXCEPTIONS set. This set is
processed once the app is created in keystone.server.application
to the flask-friendly handler.
TypeError and generic Exception are registered to an explicit
error handler that converts TypeError to ValidationError (BAD_REQUEST)
and all other Exceptions to UnexpectedError (INTERNAL SERVER ERROR).
These exceptions are then emitted in a "jsonify-ed" manner to the
client.
Two other minor changes were required:
* Unenforced API decorator had it's core functionality split into
a dedicated function that can be called in the case of an error
being raised in a "before_request" function (such as validation
in the JSON Body before request func.
* The JSON Body before request func now explicitly sets the
api to "unenforced_ok" if it is raising an exception. This
prevents the flask "was this API enforced" assertion from failing
because @unenforced_api was never run (the ValidationError was
raised prior to the resource's method being called).
Reviewed: https:/ /review. openstack. org/609796 /git.openstack. org/cgit/ openstack/ keystone/ commit/ ?id=9b052e4c059 893791dd7adc4aa 32d40ac098e788
Committed: https:/
Submitter: Zuul
Branch: master
commit 9b052e4c0598937 91dd7adc4aa32d4 0ac098e788
Author: Morgan Fainberg <email address hidden>
Date: Thu Oct 11 12:32:59 2018 -0700
Register exceptions with a Flask Error Handler
Exceptions are now handled in the Flask APP instead of in the exception. Error) are automatically exception. KEYSTONE_ API_EXCEPTIONS set. This set is server. application
legacy webob Application code (at this point that code was living
in the URL Normalizing Middleware). All Keystone API exceptions
(derived from keystone.
registered on definition with the
keystone.
processed once the app is created in keystone.
to the flask-friendly handler.
TypeError and generic Exception are registered to an explicit
error handler that converts TypeError to ValidationError (BAD_REQUEST)
and all other Exceptions to UnexpectedError (INTERNAL SERVER ERROR).
These exceptions are then emitted in a "jsonify-ed" manner to the
client.
Two other minor changes were required:
* Unenforced API decorator had it's core functionality split into
a dedicated function that can be called in the case of an error
being raised in a "before_request" function (such as validation
in the JSON Body before request func.
* The JSON Body before request func now explicitly sets the
api to "unenforced_ok" if it is raising an exception. This
prevents the flask "was this API enforced" assertion from failing
because @unenforced_api was never run (the ValidationError was
raised prior to the resource's method being called).
Change-Id: I0d0ef6a774eb86 b4769238ed34d77 03232ce86c3
Partial-Bug: #1776504