Closed supafana closed 1 month ago
I think you can use .abortSignal()
with AbortSignal.timeout()
for this (we should put this on the docs tbh):
const { data, error } = await supabase
.from('some_table')
.select()
.abortSignal(AbortSignal.timeout(3000))
We put off timeout support for now because, as noted in the MDN link, it's not possible to combine multiple signals atm (which is the way we thought about implementing it).
Feature request : How to handle timeouts
This is my first project using Supabase, and I just realised that:
If I do an
upsert
with my wifi shut down for some seconds, then I immediately get a CORS error from Firefox, and the callback inthen
is executed, in which I can access theerror
field of the passed object ({ message: "FetchError: NetworkError when attempting to fetch resource.", details: "", hint: "", … }
).If I do the same but less than seconds after cutting internet access, then, I don't get the CORS error, and it seems there is no timeout. Only when I connect back do I get the CORS error, and can handle the error in the
then
.For my UX, I need to know if that request failed in seconds. I could implement my own timeout logic in the app, e.g. if I didn't get an answer in 3 seconds show a warning that the backend is unresponsive, but I don't think that's the best way to do it.
Could supabase-js provide an option to set the timeout for fetch, either globally or per-request?
Otherwise, I've seen it is possible to provide a custom fetch implementation during the initialization, I could just provide a fetch with the timeout value that I want. I don't know if this is intended for my use-case, as setting the timeout value seems basic enough and I would have expected a simple option.
Thanks for that awesome project in any case.