react-supabase
react-supabase copied to clipboard
Promises never reject - exceptions are swallowed
Bug report
Description / Observed Behavior
Use something like useInsert and force an error (insert null value in required column). Either wrap the call in a try/catch block, or utilize the .catch syntax for callbacks. The catch block never hits. The exception is swallowed, and returned in the errors property instead. This is not the behavior I would expect, because any libraries that can be used with promises (react-toastify in my case) cannot be directly used with this library.
Expected Behavior
I would expect exceptions to propagate up as they traditionally do, or provide some means to opt-out of this behavior.
Repro Steps / Code Example
const [_, insertEvent] = useInsert<CalendarEvent>('calendar_event');
try {
const insertFunc = await insertEvent({
// insert nothing to force a validation error
})
} catch (err) {
console.log(err) //<-- this will never be hit
}
const insertFunc = await insertEvent({
// insert nothing to force a validation error
}).catch(error => {
console.log(error); // <-- this will never be hit
});
Additional Context
The issue can be worked around by wrapping the call
const insertFunc = async () => {
const { data, count, error } = await insertEvent({
// force error
})
if (error) throw error;
return { data, count };
}
This could be made suitably generic to wrap any call, but feels like this shouldn't be necessary.