Pocketbase response errors in tanstack from

Simple error handling trick to display error messages returned from a pocketbase server

November 4, 2024
Gist
const error = mutation?.error as ClientResponseError;
const pbError = error?.data?.data as Record<string, {message: string,code:string}>

useEffect(() => {
    pbError&&Object?.entries(pbError)?.forEach(([key, value]) => {
      form.setFieldMeta(key as any,(prev)=>{
        return {...prev, errorMap:{
          onChange:value?.message
        }}
      });
    });
}, [pbError]);

Copied from a tanstack form discussion 👇