supermemoryai/supermemory · error · Error

Failed to delete document

Error message

Failed to delete document

What it means

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.

Source

Thrown at packages/lib/queries.ts:105

			s.canceledAt != null &&
			(PLAN_TIERS as readonly string[]).includes(s.planId),
	)
	if (!sub) return null
	return {
		planId: sub.planId,
		endsAt: sub.currentPeriodEnd ?? sub.expiresAt ?? null,
	}
}

export const useDeleteDocument = (selectedProject: string) => {
	const queryClient = useQueryClient()

	return useMutation({
		mutationFn: async (documentId: string) => {
			// context for LLM: delete/memories/:documentId is documents delete endpoint not memories delete endpoint
			const response = await $fetch(`@delete/documents/${documentId}`)
			if (response.error) {
				throw new Error(response.error?.message || "Failed to delete document")
			}
			return response.data
		},
		onMutate: async (documentId: string) => {
			await queryClient.cancelQueries({
				queryKey: ["documents-with-memories", selectedProject],
			})

			const previousData = queryClient.getQueryData([
				"documents-with-memories",
				selectedProject,
			])

			queryClient.setQueryData(
				["documents-with-memories", selectedProject],
				(old: unknown) => {
					if (!old || typeof old !== "object") return old

View on GitHub (pinned to d436792e77)

Solutions

  1. Check response.error.message / network tab for the underlying status code (404 vs 401 vs 500) and fix the root cause
  2. Verify the documentId exists and belongs to the current project before deleting
  3. Ensure the user session/token is valid (re-login) if 401/403
  4. Handle the error in the mutation's onError and show user feedback, refetching the documents list to resync

Example fix

// before
const { mutate } = useDeleteDocument()
mutate(docId) // unhandled rejection

// after
const { mutate } = useDeleteDocument()
mutate(docId, {
  onError: (err) => toast.error(err.message),
  onSettled: () => queryClient.invalidateQueries({ queryKey: ['documents-with-memories'] }),
})
Defensive patterns

Strategy: try-catch

Try / catch

mutate(docId, { onError: (err) => { toast.error(err.message); queryClient.invalidateQueries({ queryKey: ['documents-with-memories'] }) } })

Prevention

When it happens

Trigger: 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).

Common situations: Document already deleted elsewhere, expired auth session, wrong selectedProject scope, or API version mismatch where the delete endpoint moved.

Related errors


AI-assisted analysis of supermemoryai/supermemory@d436792e77 (2026-08-28). Data as JSON: /api/errors/16e95588b237d222. Report an issue: GitHub.