Merge "Use server supplied error strings"

This commit is contained in:
Zuul 2023-12-01 17:21:10 +00:00 committed by Gerrit Code Review
commit f58fe01d6d
1 changed files with 18 additions and 6 deletions

View File

@ -90,16 +90,28 @@ class ZuulRESTClient(object):
def _check_request_status(self, req):
try:
req.raise_for_status()
msg = None
except Exception as e:
if req.status_code == 401:
raise ZuulRESTException(
'Unauthorized - your token might be invalid or expired.')
msg = \
'Unauthorized - your token might be invalid or expired.'
elif req.status_code == 403:
raise ZuulRESTException(
'Insufficient privileges to perform the action.')
msg = \
'Insufficient privileges to perform the action.'
else:
raise ZuulRESTException(
'Unknown error code %s: "%s"' % (req.status_code, e))
msg = \
'Unknown error code %s: "%s"' % (req.status_code, e)
try:
doc = req.json()
msg = '%s: %s' % (doc['error'], doc['description'])
except Exception:
pass
# This is outside the above handler in order to suppress the
# original exception (this one will still have an appropriate
# traceback; we don't need both).
if msg:
raise ZuulRESTException(msg)
def _check_scope(self, tenant):
scope = self.info.get("tenant", None)