Add logs by api
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 3m0s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 3m0s
This commit is contained in:
parent
27012a8809
commit
9113cdafc3
@ -66,15 +66,23 @@ def _do_request(action: str, body_dict: dict) -> dict:
|
||||
try:
|
||||
resp = service.json(action, {}, body)
|
||||
except Exception as e:
|
||||
error_str = str(e)
|
||||
# SDK raises Exception(resp.text.encode("utf-8")) on non-200;
|
||||
# str(e) becomes b'...' which isn't valid JSON. Decode it first.
|
||||
raw = e.args[0] if e.args else ''
|
||||
error_str = raw.decode('utf-8') if isinstance(raw, bytes) else str(raw)
|
||||
logger.warning('Assets API %s raw error: %s', action, error_str)
|
||||
try:
|
||||
error_data = json.loads(error_str)
|
||||
err_meta = error_data.get('ResponseMetadata', {}).get('Error', {})
|
||||
if err_meta:
|
||||
raise AssetsAPIError(err_meta.get('Code', 'Unknown'), err_meta.get('Message', error_str))
|
||||
err = error_data.get('error', {})
|
||||
raise AssetsAPIError(err.get('code', 'Unknown'), err.get('message', error_str))
|
||||
except (json.JSONDecodeError, AssetsAPIError):
|
||||
raise
|
||||
except Exception:
|
||||
raise AssetsAPIError('RequestError', error_str)
|
||||
pass
|
||||
raise AssetsAPIError('RequestError', error_str or 'Empty response from API')
|
||||
|
||||
data = json.loads(resp) if isinstance(resp, str) else resp
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user