Skip to content

Commit

Permalink
SP-874 Support "errors" array
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarzybok-sumoheavy committed Feb 26, 2024
1 parent 8f3b96e commit 9ec690b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 19 additions & 5 deletions src/bitpay/clients/response_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/clients/test_response_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."

0 comments on commit 9ec690b

Please sign in to comment.