Client interceptor not working for failed requests?
Description
I can't figure out if interceptors for failed network requests are broken or if I'm just not doing something right. Here I messed up the base URL for the client and added a log in the response interceptor for a status code greater than 200 but nothing is logged. I also added an interceptor for error but nothing is logged there either.
Reproducible example or configuration
https://stackblitz.com/edit/hey-api-example-jgynnupd?file=src%2FApp.tsx
OpenAPI specification (optional)
No response
System information (optional)
No response
@mrlubos this can be a bit of a problem if you want to catch network errors, which tend to happen pretty often in SPAs since the page rarely needs to reload. Is there a quick workaround to catch those errors? I thought about overriding the client’s post and get methods, but that feels a bit overkill.
I can confirm this behavior. Very annoying :(
From what I see:
- the code breaks here https://github.com/hey-api/openapi-ts/blob/dcfad92d980a43265fb9ae6316a1c0903ed0b07c/packages/custom-client/src/client.ts#L80
- The error interceptor is called way later: https://github.com/hey-api/openapi-ts/blob/dcfad92d980a43265fb9ae6316a1c0903ed0b07c/packages/custom-client/src/client.ts#L150
- Looks like error is designed for response parsing errors not fetch errors (i.e. network errors)