Handle strings as response error_message

Change-Id: I9643303973edd992066ff013a9cec21be689ae84
Closes-Bug: #1755851
This commit is contained in:
vmarkov 2018-03-14 19:01:46 +02:00
parent be4dfa504e
commit 8fc3a19e1e
1 changed files with 5 additions and 2 deletions

View File

@ -165,14 +165,17 @@ def from_response(response, url, method=None):
if "retry-after" in response.headers:
kwargs['retry_after'] = response.headers.get('retry-after')
if content_type == "application/json":
try:
body = response.json()
except ValueError:
pass
else:
desc = body.get('error_message', {}).get('faultstring')
error_message = body.get('error_message', {})
try:
desc = error_message.get('faultstring')
except AttributeError:
desc = error_message
for enhanced_cls in enhanced_classes:
if enhanced_cls.match.match(desc):
cls = enhanced_cls