File tree Expand file tree Collapse file tree 4 files changed +12
-3
lines changed
src/openapi_python_generator/language_converters/python/templates Expand file tree Collapse file tree 4 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -26,3 +26,12 @@ class APIConfig():
2626{% else %}
2727 _access_token = value
2828{% endif %}
29+
30+ class HTTPException(Exception):
31+ def __init__(self, status_code: int, message: str):
32+ self.status_code = status_code
33+ self.message = message
34+ super().__init__(f"{status_code} {message}")
35+
36+ def __str__(self):
37+ return f"{self.status_code} {self.message}"
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ with httpx.Client(base_url=base_path) as client:
2929 )
3030
3131 if response.status_code != {{ return_type.status_code }}:
32- raise Exception( f'{{ operationId }} failed with status code: {response.status_code}')
32+ raise HTTPException(response.status_code, f'{{ operationId }} failed with status code: {response.status_code}')
3333{% if return_type .complex_type %}
3434{% if return_type .list_type is none %}
3535 return {{ return_type.type.converted_type }}(**response.json())
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ def {{ operation_id }}({{ params }}) -> {% if return_type.type is none or return
2222 {% endif %}
2323 )
2424 if response.status_code != {{ return_type.status_code }}:
25- raise Exception( f'{{ operationId }} failed with status code: {response.status_code}')
25+ raise HTTPException(response.status_code, f'{{ operationId }} failed with status code: {response.status_code}')
2626{% if return_type .complex_type %}
2727{% if return_type .list_type is none %}
2828 return {{ return_type.type.converted_type }}(**response.json())
Original file line number Diff line number Diff line change @@ -3,6 +3,6 @@ import {{ library_import }}
33import json
44
55from ..models import *
6- from ..api_config import APIConfig
6+ from ..api_config import APIConfig, HTTPException
77
88{{ content | safe}}
You can’t perform that action at this time.
0 commit comments