Replies: 2 comments 2 replies
-
Yes, this is a bit tricky since default response doesn't have to describe errors. In fact, before I made that change, default response was assumed to be status 200 which was also incorrect. Perhaps a simple solution for now would be to check whether 200 is defined and if so, assume default response describes errors. |
Beta Was this translation helpful? Give feedback.
-
I also would prefer to have an error thrown-- especially since in strict TypeScript instead of when having a success that I am guaranteed to have my success response type back, I have to first check if it is not undefined. Also, I still have to check for errors for communication errors, etc. I have a lot of code with the older openapi from earlier versions that I can switch to using the treeshaking style without too much work, but this way of handling errors would cause a lot of extra work to handle this... Or I change something like this:
to
it's not the worst situation, but I'd rather not have to add those 2 lines. Of course, likely if the fetch-client did throw errors, then it would wrap the api error type in something like a RequestError type, and so, I would have to make changes there:
|
Beta Was this translation helpful? Give feedback.
-
Our spec uses "default" responses for errors per the swagger docs.
The example:
With release 0.43 which began to include default response types, the generated response type include the default response type:
Which means I now need to type check my response instead of catching an error.
I'm not sure if my use case is the same way everyone uses the
default
response in the spec. My question is:Should default response types from the spec be included in the generated TS response type? Or should it throw an error and be treated like response codes 400+? Or, maybe a config option to choose the behavior?
This is related to #500
Beta Was this translation helpful? Give feedback.
All reactions