-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REQ] [Python] Generated Python clients should be smarter about what exceptions it throws #2151
Comments
+1 to this idea |
Hi @geneticgenesis, So far the feedback has been only positive. Could you please create the PR? Cheers, Ximon (not part of the openapi-generator project, just another user) |
Hi @geneticgenesis |
Kylmakalle
pushed a commit
to Kylmakalle/openapi-generator
that referenced
this issue
Dec 4, 2020
* Subclass Python exceptions: - UnauthorizedException (401) - ForbiddenException (403) - NotFoundException (404) - ServiceException [500 - 599] Fixes OpenAPITools#2151 * add generated sample code * use Python 2 flavor inheritance * regenerate samples
spacether
pushed a commit
that referenced
this issue
Dec 5, 2020
* Subclass Python exceptions (#7321) * Subclass Python exceptions: - UnauthorizedException (401) - ForbiddenException (403) - NotFoundException (404) - ServiceException [500 - 599] Fixes #2151 * add generated sample code * use Python 2 flavor inheritance * regenerate samples * update samples Co-authored-by: Ryan Rishi <ryan@ryanrishi.com> Co-authored-by: William Cheng <wing328hk@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
In Python, its idiomatic to throw exceptions when things don't go your way. The code generated by OpenAPI Generator is consistent with this, and throws a generic
ApiException
whenever the HTTP status code returned is not between 200 and 299.However, it's also idiomatic to throw meaningful, actionable exceptions, for example in the case where an API 404s because an unknown object has been requested, it would be idiomatic to throw a
NotFoundException
. In the OpenAPI Generator generated python, While you can work out that the error was a 404 by looking at the HTTP data in theApiException
, this is inelegant.Describe the solution you'd like
We can improve the default behavior of the code generated by:
ApiException
NotFoundException
UnauthorizedException
ForbiddenException
ServiceException
NotFoundException
is thrown on 404sUnauthorizedException
is thrown on 401sForbiddenException
is thrown on 403sServiceException
is thrown on 500 => 599Describe alternatives you've considered
None
Additional context
I have updated templates which generate this. If the consensus is that this is useful, please let me know, and I'll submit a PR with the changes.
Cheers,
The text was updated successfully, but these errors were encountered: