Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #2151
Closed
Open
Issue created Feb 13, 2019 by Administrator@rootContributor

[REQ] [Python] Generated Python clients should be smarter about what exceptions it throws

Created by: philcluff

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 the ApiException, this is inelegant.

Describe the solution you'd like

We can improve the default behavior of the code generated by:

  • Create 4 new subclasses of ApiException
    • NotFoundException
    • UnauthorizedException
    • ForbiddenException
    • ServiceException
  • Update rest.py so that...
    • NotFoundException is thrown on 404s
    • UnauthorizedException is thrown on 401s
    • ForbiddenException is thrown on 403s
    • ServiceException is thrown on 500 => 599

Describe 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,

Assignee
Assign to
Time tracking