{"record":{"id":"16e95588b237d222","repo":"supermemoryai/supermemory","slug":"failed-to-delete-document","errorCode":null,"errorMessage":"Failed to delete document","messagePattern":"Failed to delete document","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/lib/queries.ts","lineNumber":105,"sourceCode":"\t\t\ts.canceledAt != null &&\n\t\t\t(PLAN_TIERS as readonly string[]).includes(s.planId),\n\t)\n\tif (!sub) return null\n\treturn {\n\t\tplanId: sub.planId,\n\t\tendsAt: sub.currentPeriodEnd ?? sub.expiresAt ?? null,\n\t}\n}\n\nexport const useDeleteDocument = (selectedProject: string) => {\n\tconst queryClient = useQueryClient()\n\n\treturn useMutation({\n\t\tmutationFn: async (documentId: string) => {\n\t\t\t// context for LLM: delete/memories/:documentId is documents delete endpoint not memories delete endpoint\n\t\t\tconst response = await $fetch(`@delete/documents/${documentId}`)\n\t\t\tif (response.error) {\n\t\t\t\tthrow new Error(response.error?.message || \"Failed to delete document\")\n\t\t\t}\n\t\t\treturn response.data\n\t\t},\n\t\tonMutate: async (documentId: string) => {\n\t\t\tawait queryClient.cancelQueries({\n\t\t\t\tqueryKey: [\"documents-with-memories\", selectedProject],\n\t\t\t})\n\n\t\t\tconst previousData = queryClient.getQueryData([\n\t\t\t\t\"documents-with-memories\",\n\t\t\t\tselectedProject,\n\t\t\t])\n\n\t\t\tqueryClient.setQueryData(\n\t\t\t\t[\"documents-with-memories\", selectedProject],\n\t\t\t\t(old: unknown) => {\n\t\t\t\t\tif (!old || typeof old !== \"object\") return old\n","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/supermemoryai/supermemory/blob/d436792e777a99865939dd543c8d1a16d57f54ec/packages/lib/queries.ts#L87-L123","documentation":"Thrown by the useDeleteDocument React Query mutation when the DELETE /documents/:documentId request returns an error payload. It surfaces whatever message the API returned, falling back to this generic string. It is a client-side wrapper around a failed HTTP delete operation.","triggerScenarios":"Calling the mutate function of useDeleteDocument and the $fetch('@delete/documents/{id}') request returns a non-success response with an error body (e.g. 404 for a nonexistent document, 401/403 for auth issues, or a server-side 500).","commonSituations":"Document already deleted elsewhere, expired auth session, wrong selectedProject scope, or API version mismatch where the delete endpoint moved.","solutions":["Check response.error.message / network tab for the underlying status code (404 vs 401 vs 500) and fix the root cause","Verify the documentId exists and belongs to the current project before deleting","Ensure the user session/token is valid (re-login) if 401/403","Handle the error in the mutation's onError and show user feedback, refetching the documents list to resync"],"exampleFix":"// before\nconst { mutate } = useDeleteDocument()\nmutate(docId) // unhandled rejection\n\n// after\nconst { mutate } = useDeleteDocument()\nmutate(docId, {\n  onError: (err) => toast.error(err.message),\n  onSettled: () => queryClient.invalidateQueries({ queryKey: ['documents-with-memories'] }),\n})","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"mutate(docId, { onError: (err) => { toast.error(err.message); queryClient.invalidateQueries({ queryKey: ['documents-with-memories'] }) } })","preventionTips":["Invalidate/refetch the documents list on error to resync UI state","Check document existence and permissions before offering delete UI"],"tags":["react-query","http","delete","documents"],"backgroundTag":"api-request-failed","analyzedSha":"d436792e777a99865939dd543c8d1a16d57f54ec","analyzedAt":"2026-08-28T18:04:46.947Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}