Repository: openapi-generators/openapi-python-client (language: python)

Issue:
`UnexpectedStatus` contains an uninformative message
### Problem

Now when we set
```python
raise_on_unexpected_status=True
```
in the client, we will only see `Unexpected status code: 400` (or smt like) when any unexpected status is received. But in fact, this is an uninformative message. To find out what is the reason for this exception, we should try to reproduce the situation ourselves and check the content of the response. Sometimes it's very difficult.

## Solution I'd propose

Maybe add response content to text of [UnexpectedStatus](https://github.com/openapi-generators/openapi-python-client/blob/a719c87b7d278135c475d8123aa144651fa55523/openapi_python_client/templates/errors.py.jinja#L10) exception? Or add some flag that allows us to show the contents of the response when we receive an unexpected status code?


Discussion / hints:

Fix patch:
diff --git a/.changeset/add_response_content_to_unexpectedstatus_exception.md b/.changeset/add_response_content_to_unexpectedstatus_exception.md
new file mode 100644
index 000000000..3cb59af6e
--- /dev/null
+++ b/.changeset/add_response_content_to_unexpectedstatus_exception.md
@@ -0,0 +1,9 @@
+---
+default: minor
+---
+
+# Add response content to `UnexpectedStatus` exception
+
+The error message for `UnexpectedStatus` exceptions will now include the UTF-8 decoded (ignoring errors) body of the response.
+
+PR #989 implements #840. Thanks @harabat!
diff --git a/openapi_python_client/templates/errors.py.jinja b/openapi_python_client/templates/errors.py.jinja
index 4042ff730..b912123d0 100644
--- a/openapi_python_client/templates/errors.py.jinja
+++ b/openapi_python_client/templates/errors.py.jinja
@@ -7,6 +7,8 @@ class UnexpectedStatus(Exception):
         self.status_code = status_code
         self.content = content
 
-        super().__init__(f"Unexpected status code: {status_code}")
+        super().__init__(
+            f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}"
+        )
 
 __all__ = ["UnexpectedStatus"]


Test patch:
diff --git a/end_to_end_tests/golden-record/my_test_api_client/errors.py b/end_to_end_tests/golden-record/my_test_api_client/errors.py
index be532ad00..5f92e76ac 100644
--- a/end_to_end_tests/golden-record/my_test_api_client/errors.py
+++ b/end_to_end_tests/golden-record/my_test_api_client/errors.py
@@ -8,7 +8,9 @@ def __init__(self, status_code: int, content: bytes):
         self.status_code = status_code
         self.content = content
 
-        super().__init__(f"Unexpected status code: {status_code}")
+        super().__init__(
+            f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}"
+        )
 
 
 __all__ = ["UnexpectedStatus"]
diff --git a/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/errors.py b/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/errors.py
index be532ad00..5f92e76ac 100644
--- a/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/errors.py
+++ b/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/errors.py
@@ -8,7 +8,9 @@ def __init__(self, status_code: int, content: bytes):
         self.status_code = status_code
         self.content = content
 
-        super().__init__(f"Unexpected status code: {status_code}")
+        super().__init__(
+            f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}"
+        )
 
 
 __all__ = ["UnexpectedStatus"]
diff --git a/integration-tests/integration_tests/errors.py b/integration-tests/integration_tests/errors.py
index be532ad00..5f92e76ac 100644
--- a/integration-tests/integration_tests/errors.py
+++ b/integration-tests/integration_tests/errors.py
@@ -8,7 +8,9 @@ def __init__(self, status_code: int, content: bytes):
         self.status_code = status_code
         self.content = content
 
-        super().__init__(f"Unexpected status code: {status_code}")
+        super().__init__(
+            f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}"
+        )
 
 
 __all__ = ["UnexpectedStatus"]