Skip to content

fix(supabase): report errors from custom create/update/delete to onError - #675

Open
LinusOssmann wants to merge 1 commit into
LegendApp:mainfrom
LinusOssmann:fix/supabase-custom-write-errors
Open

LinusOssmann wants to merge 1 commit into
LegendApp:mainfrom
LinusOssmann:fix/supabase-custom-write-errors

Conversation

@LinusOssmann

Copy link
Copy Markdown

Problem

wrapSupabaseFn is used for custom list, create, update and delete functions, but it always treats the first argument as params: const { onError } = params. syncedCrud calls the write functions as fn(input, params), so for writes onError is read from the row and is undefined. When a custom write returns { error }, the wrapper throws TypeError: onError is not a function. The user's onError receives that TypeError with source: 'set' instead of the server error with source: 'create'/'update', and there is no revert. Server rejections of custom writes (RLS, constraints, …) are effectively invisible.

Fix

Keep the existing behavior for list. For writes, take onError from the second argument and route the error through handleSupabaseError with the same params the built-in create/update/delete pass (type: 'set', input, revert).

Test

tests/supabase-custom-fns.test.ts: a custom create and a custom update that return an RLS error. On main onError receives "onError is not a function"; with the fix it receives the server message, the right source and a revert function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant