Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Exceptions on Error Codes #966

Unanswered
wheresthecode asked this question in Q&A
Discussion options

Hi! Great library! I just wanted to give a suggestion to support throwing exceptions when an API returns non-2** results. FastAPIs can return 422 and the HTTPValidationError type on failure. It would be great if this was handled by the client API throwing an exception. As it is currently implemented all the APIs return Response[MyResult | HTTPValidationError]. Would be great if it always returned Response[MyResult] or just threw an exception. Might also consider just returning MyResult.

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

I'm also curious about this choice. I found it surprising when I first examined the code generated by this library, since it doesn't seem like idiomatic Python to me, so I'm wondering what the reasoning behind it was.

A particular consideration for my use case: it's not certain that consumers of our generated code will be effectively enforcing type-checking (some will be, some won't be is my guess). In the case where they aren't, then using a union of [ok, error] rather than an exception that's raised on error increases the chances that they'll get some inscrutable downstream error because they thought they had a success response but actually had a failure one, and forgot to check which it was.

You must be logged in to vote
1 reply
Comment options

Ah, I see there's history here in #491 and related discussions. Let me read up on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /