You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the Python generator provides custom exception classes for the following HTTP error codes:
400 (Bad Request)
401 (Unauthorized)
403 (Forbidden)
404 (Not Found)
However, other common HTTP status codes like 409 (Conflict) and 422 (Unprocessable Entity) are not handled by custom exception classes:
409 is often used to indicate a conflict in the request, such as trying to create a resource that already exists.
422 is commonly used in frameworks like FastAPI to signal validation errors in the request payload.
The lack of dedicated exception classes for these codes makes error handling less intuitive, because developers need to catch a generic ApiException in order to inspect and classify the error.
Describe the solution you'd like
Add custom exception classes for HTTP status codes 409 and 422, similar to the existing custom exceptions for other 4XX codes. More specifically, something like:
This modification would align with the current implementation while providing more convenient and meaningful error handling for these particular HTTP status codes.
Describe alternatives you've considered
The current alternative is going with something like:
try:
# API call expected to produce a 409 or 422 goes here.exceptApiExceptionase:
ife.status==409:
# Code expected to handle the 409 error goes here.elife.status==422:
# Code expected to handle the 422 error goes here.else:
raise
Although this code is valid, it's not as elegant as using dedicated exception classes. The need to manually inspect the status field to handle specific cases adds unnecessary boilerplate and detracts from the clarity of the error-handling logic.
Additional context
I'm ready to submit a PR with these changes for consideration.
The text was updated successfully, but these errors were encountered:
@OM-HASE I'm not sure your PR is complete. Please have a look at #7321 for how the previous change was implemented. It included changes to the petstore-api examples.
Is your feature request related to a problem? Please describe.
This issue expands on #2151.
Currently, the Python generator provides custom exception classes for the following HTTP error codes:
However, other common HTTP status codes like 409 (Conflict) and 422 (Unprocessable Entity) are not handled by custom exception classes:
The lack of dedicated exception classes for these codes makes error handling less intuitive, because developers need to catch a generic
ApiException
in order to inspect and classify the error.Describe the solution you'd like
Add custom exception classes for HTTP status codes
409
and422
, similar to the existing custom exceptions for other4XX
codes. More specifically, something like:This modification would align with the current implementation while providing more convenient and meaningful error handling for these particular HTTP status codes.
Describe alternatives you've considered
The current alternative is going with something like:
Although this code is valid, it's not as elegant as using dedicated exception classes. The need to manually inspect the
status
field to handle specific cases adds unnecessary boilerplate and detracts from the clarity of the error-handling logic.Additional context
I'm ready to submit a PR with these changes for consideration.
The text was updated successfully, but these errors were encountered: