Replies: 2 comments 3 replies
-
@olliejm that sounds reasonable to me. Will need to discuss further and decide how exactly we want this to function. Cc: @mrlubos |
Beta Was this translation helpful? Give feedback.
0 replies
-
I see @olliejm. Frankly this might take a while to implement as we have other priorities, but would something like openapi-fetch API work for you? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
After #282 was fixed (very promptly, thanks!), I just realised that my original intended use case - to avoid writing
try/catch
to deal withApiError
by settingserviceResponse: 'response'
and checking status - would not work, as the generated code always throws on an error for4xx/5xx
codes.I'm wondering if it makes sense, probably only when
serviceResponse: 'response'
is set, that we can optionally specify status codes which should not throw because the caller expects them.My use case is, that in a Next.js application in several places I may make an API call and it would be convenient to be able to do something like:
I would argue that for
4xx
status codes in particular, you may often expect e.g. a 404 if a URL contains an invalid or since-removed ID, or say a 429 if the server is rate-limiting. I wouldn't really consider these exceptional, but something that just determines the UI state, like going to a 404 page, doing a redirect, showing the user their form data was refused, that they aren't authorised, and so on.For server-side
5xx
status codes I think it would be more reasonable to throw by default.Any thoughts on this? It's obviously not really a huge issue to
try/catch
this, but just feels a little off to me when I'm trying to handle cases I expect, and not unexpected errors.I would propose the presence of a
requestThrowStatusCodes
and/orrequestDontThrowStatusCodes
, followed by either a) all existing throwing codes will throw by default, or b) 4xx don't throw and 5xx do throw. I realise changing default throwing behaviour would be breaking, so maybe that would also be toggled by another setting to opt-in to new defaults.Beta Was this translation helpful? Give feedback.
All reactions