Skip to content

Commit 8eb432a

Browse files
OM-HASEtimon-sbr
authored andcommitted
Fix(Python): Add custom exceptions for HTTP status codes 409 (Conflict) and 422 (Unprocessable Entity) OpenAPITools#20244 (OpenAPITools#20251)
* Update exceptions.mustache * Fix(Python): Add custom exceptions for HTTP status codes 409 (Conflict) and 422 (Unprocessable Entity) OpenAPITools#20244
1 parent 59c6140 commit 8eb432a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

modules/openapi-generator/src/main/resources/python/exceptions.mustache

+17
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ class ApiException(OpenApiException):
140140
if http_resp.status == 404:
141141
raise NotFoundException(http_resp=http_resp, body=body, data=data)
142142

143+
# Added new conditions for 409 and 422
144+
if http_resp.status == 409:
145+
raise ConflictException(http_resp=http_resp, body=body, data=data)
146+
147+
if http_resp.status == 422:
148+
raise UnprocessableEntityException(http_resp=http_resp, body=body, data=data)
149+
143150
if 500 <= http_resp.status <= 599:
144151
raise ServiceException(http_resp=http_resp, body=body, data=data)
145152
raise ApiException(http_resp=http_resp, body=body, data=data)
@@ -178,6 +185,16 @@ class ServiceException(ApiException):
178185
pass
179186

180187

188+
class ConflictException(ApiException):
189+
"""Exception for HTTP 409 Conflict."""
190+
pass
191+
192+
193+
class UnprocessableEntityException(ApiException):
194+
"""Exception for HTTP 422 Unprocessable Entity."""
195+
pass
196+
197+
181198
def render_path(path_to_item):
182199
"""Returns a string representation of a path"""
183200
result = ""

samples/openapi3/client/petstore/python/petstore_api/exceptions.py

+16
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ def from_response(
150150
if http_resp.status == 404:
151151
raise NotFoundException(http_resp=http_resp, body=body, data=data)
152152

153+
# Added new exception classes for 409 and 422
154+
155+
if http_resp.status == 409:
156+
raise ConflictException(http_resp=http_resp, body=body, data=data)
157+
158+
if http_resp.status == 422:
159+
raise UnprocessableEntityException(http_resp=http_resp, body=body, data=data)
160+
153161
if 500 <= http_resp.status <= 599:
154162
raise ServiceException(http_resp=http_resp, body=body, data=data)
155163
raise ApiException(http_resp=http_resp, body=body, data=data)
@@ -183,6 +191,14 @@ class UnauthorizedException(ApiException):
183191
class ForbiddenException(ApiException):
184192
pass
185193

194+
class ConflictException(ApiException):
195+
"""Exception raised for HTTP 409 Conflict errors."""
196+
pass
197+
198+
199+
class UnprocessableEntityException(ApiException):
200+
"""Exception raised for HTTP 422 Unprocessable Entity errors."""
201+
pass
186202

187203
class ServiceException(ApiException):
188204
pass

0 commit comments

Comments
 (0)