{"record":{"id":"996ca296c11f83ca","repo":"different-ai/openwork","slug":"failed-to-delete-collection-response-status","errorCode":null,"errorMessage":"Failed to delete collection (${response.status}).","messagePattern":"Failed to delete collection \\((.+?)\\)\\.","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/marketplace-data.tsx","lineNumber":508,"sourceCode":"      queryClient.invalidateQueries({ queryKey: marketplaceQueryKeys.resolved(marketplace.id) });\n    },\n  });\n}\n\nexport function useDeleteMarketplace() {\n  const queryClient = useQueryClient();\n  const { runReauthableAction } = useOrgDashboard();\n\n  return useMutation({\n    mutationFn: async (marketplaceId: string): Promise<string> => {\n      await runReauthableAction(\"delete-marketplace\", async () => {\n        const { response, payload } = await requestJson(\n          `/v1/marketplaces/${encodeURIComponent(marketplaceId)}/delete`,\n          { method: \"POST\" },\n          15000,\n        );\n        if (!response.ok) {\n          throw getRequestError(payload, response, `Failed to delete collection (${response.status}).`);\n        }\n      });\n      return marketplaceId;\n    },\n    onSuccess: (marketplaceId) => {\n      queryClient.removeQueries({ queryKey: marketplaceQueryKeys.resolved(marketplaceId) });\n      queryClient.invalidateQueries({ queryKey: marketplaceQueryKeys.list() });\n    },\n  });\n}\n\nexport function formatMarketplaceTimestamp(value: string | null): string {\n  if (!value) return \"Recently added\";\n  const date = new Date(value);\n  if (Number.isNaN(date.getTime())) return \"Recently added\";\n  return new Intl.DateTimeFormat(\"en-US\", {\n    month: \"short\",\n    day: \"numeric\",","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/marketplace-data.tsx#L490-L526","documentation":"Thrown by useDeleteMarketplace when POST /v1/marketplaces/:id/delete returns a non-ok status. getRequestError substitutes the server's error message or the fallback 'Failed to delete collection (<status>)'. The query's onSuccess cleanup (removeQueries) never runs because the throw happens first, so cached data stays as-is.","triggerScenarios":"Non-ok response from the delete endpoint (15000ms timeout): 403 when the caller is not an owner/admin of the collection, 404 when it was already deleted, 409 when the server refuses deletion (e.g., plugins still published), 401 for expired sessions, 5xx for server faults.","commonSituations":"Trying to delete a shared/org collection without owner rights; double-click delete causing the second 404; server-side referential-integrity rules blocking deletion; expired Den session.","solutions":["For 403, confirm the user has owner/admin rights on the collection before deleting.","For 404, treat as already-deleted: invalidate/remove the marketplace queries and refresh the UI.","For 409, remove or reassign dependent resources (published plugins) and retry.","For 401, re-authenticate; for 5xx, retry with backoff and check Den server health.","Check isReauthRequiredError to trigger the re-auth flow."],"exampleFix":"// before\nawait deleteMarketplace(id);\n// after\ntry {\n  await deleteMarketplace(id);\n} catch (err) {\n  if (isReauthRequiredError(err)) { startReauth(); }\n  else if (/\\(404\\)/.test(err.message)) { queryClient.removeQueries({ queryKey: marketplaceQueryKeys.resolved(id) }); }\n  else setDeleteError(err.message);\n}","handlingStrategy":"try-catch","validationCode":"// before deleteMarketplace\nif (!marketplaceId) throw new Error(\"Missing collection id\");\nif (!canManage(marketplace)) throw new Error(\"You do not have permission to delete this collection\");","typeGuard":"function isAlreadyDeleted(err: unknown): boolean {\n  return err instanceof Error && /\\(404\\)/.test(err.message);\n}","tryCatchPattern":"try {\n  await deleteMarketplace(id);\n} catch (err) {\n  if (isReauthRequiredError(err)) startReauth();\n  else if (isAlreadyDeleted(err)) { queryClient.removeQueries({ queryKey: marketplaceQueryKeys.resolved(id) }); }\n  else showError(err.message);\n}","preventionTips":["Disable the delete button for users without owner/admin rights","Guard against double-submit (disable while pending) to avoid secondary 404s","Show a confirm dialog listing consequences before delete","After any 404, purge local cache for the id and refetch the list"],"tags":["http","den-api","marketplace"],"backgroundTag":"http-request-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}