Skip to content

Commit b261f0c

Browse files
authored
Merge pull request #237 from EasyPost/concatenate_error_message
fix: concatenates error.message if it is a list
2 parents ed096c0 + 8600f1f commit b261f0c

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## NEXT RELEASE
4+
5+
- Concatenates `error.message` if it incorrectly comes back from the API as a list
6+
37
## v7.6.0 (2022-09-21)
48

59
- Adds support to pass `end_shipper_id` on the buy call of a Shipment

easypost/error.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
class Error(Exception):
99
def __init__(
1010
self,
11-
message: Optional[str] = None,
11+
message: Optional[
12+
Union[str, list]
13+
] = None, # message should be a string but can sometimes incorrectly come back as a list
1214
http_status: Optional[int] = None,
1315
http_body: Optional[Union[str, bytes]] = None,
1416
original_exception: Optional[Exception] = None,
1517
):
1618
super(Error, self).__init__(message)
17-
self.message = message
19+
self.message = ", ".join(message) if type(message) == list else message
1820
self.http_status = http_status
1921
self.http_body = http_body
2022
self.original_exception = original_exception

tests/test_error.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,12 @@ def test_error_no_json():
2121
error = easypost.Error(http_body="bad json")
2222

2323
assert error.json_body is None
24+
25+
26+
def test_error_list_message():
27+
"""Tests that we concatenate error messages that are a list (they should be a string from the
28+
API but aren't always so we protect against that here).
29+
"""
30+
error = easypost.Error(message=["Error1", "Error2"])
31+
32+
assert error.message == "Error1, Error2"

0 commit comments

Comments
 (0)