Exceptions on Error Codes #966
Replies: 1 comment 1 reply
-
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. |
Beta Was this translation helpful? Give feedback.
-
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.
Beta Was this translation helpful? Give feedback.
All reactions