Skip to content

Commit c437e41

Browse files
harabatharabatdbanty
authored
Add response content to UnexpectedStatus exception (#989)
Fixes #839 and #840 This is a simple change that adds the response content to the `UnexpectedStatus` exception, which is currently the most upvoted feature in [Discussions](https://github.com/openapi-generators/openapi-python-client/discussions). --------- Co-authored-by: harabat <[email protected]> Co-authored-by: Dylan Anthony <[email protected]> Co-authored-by: Dylan Anthony <[email protected]>
1 parent 88ffbd6 commit c437e41

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
default: minor
3+
---
4+
5+
# Add response content to `UnexpectedStatus` exception
6+
7+
The error message for `UnexpectedStatus` exceptions will now include the UTF-8 decoded (ignoring errors) body of the response.
8+
9+
PR #989 implements #840. Thanks @harabat!

end_to_end_tests/golden-record/my_test_api_client/errors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ def __init__(self, status_code: int, content: bytes):
88
self.status_code = status_code
99
self.content = content
1010

11-
super().__init__(f"Unexpected status code: {status_code}")
11+
super().__init__(
12+
f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}"
13+
)
1214

1315

1416
__all__ = ["UnexpectedStatus"]

end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/errors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ def __init__(self, status_code: int, content: bytes):
88
self.status_code = status_code
99
self.content = content
1010

11-
super().__init__(f"Unexpected status code: {status_code}")
11+
super().__init__(
12+
f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}"
13+
)
1214

1315

1416
__all__ = ["UnexpectedStatus"]

integration-tests/integration_tests/errors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ def __init__(self, status_code: int, content: bytes):
88
self.status_code = status_code
99
self.content = content
1010

11-
super().__init__(f"Unexpected status code: {status_code}")
11+
super().__init__(
12+
f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}"
13+
)
1214

1315

1416
__all__ = ["UnexpectedStatus"]

openapi_python_client/templates/errors.py.jinja

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ class UnexpectedStatus(Exception):
77
self.status_code = status_code
88
self.content = content
99

10-
super().__init__(f"Unexpected status code: {status_code}")
10+
super().__init__(
11+
f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}"
12+
)
1113

1214
__all__ = ["UnexpectedStatus"]

0 commit comments

Comments
 (0)