In placement API send microversion header when error
If there is an exception in the placement API application we still need to send the openstack-api-version header in the response: errors are versioned too. Therefore catch the exception, add to its headers and then reraise the exception. This was a problem identified in the review of the initial framing of the placement API but left for a later patch. This is that later patch. Change-Id: Ib83acbf74907fd9dcbdd4b0a9271ad4bae1c21b1 Partially-Implements: blueprint generic-resource-pools
This commit is contained in:
parent
fb190f30a9
commit
2f7109764c
@ -72,8 +72,7 @@ class MicroversionMiddleware(object):
|
||||
@webob.dec.wsgify
|
||||
def __call__(self, req):
|
||||
try:
|
||||
req.environ[MICROVERSION_ENVIRON] = extract_version(
|
||||
req.headers)
|
||||
microversion = extract_version(req.headers)
|
||||
except ValueError as exc:
|
||||
raise webob.exc.HTTPNotAcceptable(
|
||||
'Invalid microversion: %s' % exc,
|
||||
@ -82,10 +81,20 @@ class MicroversionMiddleware(object):
|
||||
raise webob.exc.HTTPBadRequest(
|
||||
'Invalid microversion: %s' % exc,
|
||||
json_formatter=util.json_error_formatter)
|
||||
response = req.get_response(self.application)
|
||||
response.headers.add(Version.HEADER,
|
||||
'%s %s' % (SERVICE_TYPE,
|
||||
req.environ[MICROVERSION_ENVIRON]))
|
||||
|
||||
req.environ[MICROVERSION_ENVIRON] = microversion
|
||||
microversion_header = '%s %s' % (SERVICE_TYPE, microversion)
|
||||
|
||||
try:
|
||||
response = req.get_response(self.application)
|
||||
except webob.exc.HTTPError as exc:
|
||||
# If there was an error in the application we still need
|
||||
# to send the microversion header, so add the header and
|
||||
# re-raise the exception.
|
||||
exc.headers.add(Version.HEADER, microversion_header)
|
||||
raise exc
|
||||
|
||||
response.headers.add(Version.HEADER, microversion_header)
|
||||
response.headers.add('vary', Version.HEADER)
|
||||
return response
|
||||
|
||||
|
@ -71,3 +71,9 @@ tests:
|
||||
status: 400
|
||||
response_strings:
|
||||
- "invalid version string: 1.2.3"
|
||||
|
||||
- name: error in application produces microversion headers
|
||||
POST: /
|
||||
status: 405
|
||||
response_headers:
|
||||
openstack-api-version: placement 1.0
|
||||
|
Loading…
Reference in New Issue
Block a user