-
Notifications
You must be signed in to change notification settings - Fork 557
Description
Chore
add error handling callback in createClient, or have a standardized type that supabase calls adhere to. (ex. they should all return { data: T, error: SupabaseError }
Describe the chore
I'm writing a util that handles supabase errors, so instead of doing const { data, error} = await suapabase.callSomething() I can handle the errors automatically. But there are AuthErrors, PostgressErrors, and now i'm hitting OAuthErrors which are different somehow even though it conforms to the same response type as the other errors?
It would be really nice if there was just one error type that users could specify if needed but was general enough that we can just grab the errors and expect data to come back without errors (unless we re-threw them)
Additional context
Add any other context or screenshots that help clarify the task.
Here is the function I have that works so far for most calls:
export function handleSupabaseErrorAllowNull<T>(
result: {
data?: T
error: AuthError | PostgrestError | null
},
description?: string,
): T | null {
const { data, error } = result
if (error) {
if (description) {
// do something
}
throw error
}
return data || null
}
passing an oauth function in here throws a type error though because of.... I'm guessing I need a new result type, but it would be easier if I could just pass all supabase calls in here and not worry about it