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 the ApiException
, this is inelegant.
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 => 599None
Additional contextI 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,
tomghyselinck, qbedard, jlumbroso, bbkane, mikelfo and 17 more
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4