diff --git a/Automat/automat/core.py b/Automat/automat/core.py index b632e73..bcac2f0 100644 --- a/Automat/automat/core.py +++ b/Automat/automat/core.py @@ -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 {} diff --git a/Automat/automat/tests/test_core.py b/Automat/automat/tests/test_core.py index 1bc8229..d7e215b 100644 --- a/Automat/automat/tests/test_core.py +++ b/Automat/automat/tests/test_core.py @@ -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 @@ -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() \ No newline at end of file + assert output == resp3.json() \ No newline at end of file diff --git a/Automat/automat/util/async_client.py b/Automat/automat/util/async_client.py index 7e3570c..e665fd2 100644 --- a/Automat/automat/util/async_client.py +++ b/Automat/automat/util/async_client.py @@ -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()) @@ -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()) @@ -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()