Add default error handler and serializer

This patch set adds default error handler and serializer to
Armada's server.py which mirrors the Shipyard pattern [0].

Exceptions that inherit from ArmadaAPIException and
ArmadaBaseException alike will be formatted and serialized
via default_exception_handler and default_error_serializer
respectively.

[0] http://git.openstack.org/cgit/openstack/airship-shipyard/tree/src/bin/shipyard_airflow/shipyard_airflow/control/api.py#n99

Change-Id: I75c5d419221d46eef0fcb9930478349280ac4e41
This commit is contained in:
Felipe Monteiro 2018-10-14 11:37:02 -04:00
parent 8927c12f21
commit 90e42b5710
1 changed files with 10 additions and 0 deletions

View File

@ -31,6 +31,7 @@ from armada.api.controller.tiller import Release
from armada.api.controller.tiller import Status
from armada.api.controller.validation import Validate
from armada.api.controller.versions import Versions
from armada.exceptions import base_exception as exceptions
conf.set_app_default_configs()
CONF = cfg.CONF
@ -76,6 +77,15 @@ def create(enable_middleware=CONF.middleware):
# Initialize policy config options.
policy.Enforcer(CONF)
# Error handlers (FILO handling)
api.add_error_handler(exceptions.ArmadaBaseException,
exceptions.default_exception_handler)
api.add_error_handler(exceptions.ArmadaAPIException,
exceptions.ArmadaAPIException.handle)
# Built-in error serializer
api.set_error_serializer(exceptions.default_error_serializer)
return api