diff --git a/src/bitpay/clients/response_parser.py b/src/bitpay/clients/response_parser.py index 0230c3f..73a536d 100644 --- a/src/bitpay/clients/response_parser.py +++ b/src/bitpay/clients/response_parser.py @@ -38,13 +38,27 @@ def response_to_json_string(response: Response) -> Any: ) if "errors" in response_obj: - message = "" + final_message = "" for error in response_obj["errors"]: - if message == "": - message += str(error["error"]) + error_value = error.get('error', '') + param_value = error.get('param', '') + + if error_value.endswith('.'): + error_value = error_value[:-1] + + if error_value: + result = f"{error_value} {param_value}".strip() else: - message += " " + str(error["error"]) - BitPayExceptionProvider.throw_api_exception_with_message(message) + result = param_value.strip() + + if not result.endswith('.'): + result += '.' + + if not final_message == "": + result = " " + result + + final_message += result + BitPayExceptionProvider.throw_api_exception_with_message(final_message) if "success" in response_obj: return response_obj["success"] diff --git a/tests/unit/clients/test_response_parser.py b/tests/unit/clients/test_response_parser.py index 2aaac64..1747e0d 100644 --- a/tests/unit/clients/test_response_parser.py +++ b/tests/unit/clients/test_response_parser.py @@ -26,4 +26,4 @@ def test_handle_multiple_errors(mocker): response.json.return_value = response_json ResponseParser.response_to_json_string(response) - assert str(exc_info.value) == "Missing required parameter. Missing required parameter." + assert str(exc_info.value) == "Missing required parameter price. Missing required parameter currency."