Skip to content

Commit

Permalink
fixing up some leftover changes for the json change, reverting some e…
Browse files Browse the repository at this point in the history
…rror reporting to report the exact error json from plater
  • Loading branch information
EvanDietzMorris committed Oct 24, 2024
1 parent 64e0997 commit b6da706
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
8 changes: 4 additions & 4 deletions Automat/automat/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ async def get_swagger_paths(server_url, tag, timeout=5*6):
open_api_path = '/openapi.json'
full_path = f'http://{server_url}{open_api_path}'
response, status_code = await async_get_json(full_path, timeout=timeout)
if 'error' in response:
logger.error(response['error'])
return {}
logger.debug(response)
return {tag: response}
if status_code == 200:
return {tag: json.loads(response)}
else:
return {}



Expand Down
3 changes: 2 additions & 1 deletion Automat/automat/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def assertion_fun_412(url, **kwargs):
payload = json.loads(kwargs['data'].decode('utf-8'))
assert payload == input
return CallbackResult(status=412, payload=output)

def assertion_fun_500(url, **kwargs):
payload = json.loads(kwargs['data'].decode('utf-8'))
assert payload == input
Expand All @@ -108,4 +109,4 @@ def assertion_fun_500(url, **kwargs):
assert resp2.status_code == 412
assert output == resp2.json()
assert resp3.status_code == 500
assert output == resp3.json()
assert output == resp3.json()
16 changes: 7 additions & 9 deletions Automat/automat/util/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ async def async_get_json(url, headers=None, timeout=5*6):
# there's no need to unpack and repack it
return await response.text(), 200
else:
error = f"Plater {url} returned an unsuccessful status code ({response.status})."
response_text = await response.text()
error = f"Plater {url} returned an unsuccessful status code ({response.status}): {response_text}."
logger.error(error)
return json.dumps({'error': error,
'code': response.status,
'response': await response.text()}), response.status
return response_text, response.status
except aiohttp.ClientError as e:
logger.error(f"Error contacting {url} -- {e}")
logger.info(traceback.print_exc())
Expand All @@ -50,11 +49,10 @@ async def async_post_json(url, headers=None, body='', timeout=5*6):
# there's no need to unpack and repack it
return await response.text(), 200
else:
error = f"Plater {url} returned an unsuccessful status code ({response.status})."
response_text = await response.text()
error = f"Plater {url} returned an unsuccessful status code ({response.status}): {response_text}."
logger.error(error)
return json.dumps({'error': error,
'code': response.status,
'response': await response.text()}), response.status
return response_text, response.status
except aiohttp.ClientError as e:
logger.error(f"Error contacting {url} -- {e}")
logger.info(traceback.print_exc())
Expand Down Expand Up @@ -87,7 +85,7 @@ async def async_get_response(url, headers=None, timeout=5*60):
async with session.get(url, headers=headers) as response:
try:
json = await response.json()
except JSONDecodeError:
except json.JSONDecodeError:
json = {}
try:
text = await response.text()
Expand Down

0 comments on commit b6da706

Please sign in to comment.