{"record":{"id":"572b9abd926688d6","repo":"Mintplex-Labs/anything-llm","slug":"not-found-572b9a","errorCode":null,"errorMessage":"Not Found","messagePattern":"Not Found","errorType":"http","errorClass":null,"httpStatus":404,"severity":"error","filePath":"server/endpoints/utils.js","lineNumber":53,"sourceCode":"  app.post(\n    \"/export-chat/:type\",\n    [validatedRequest, flexUserRoleValid([ROLES.all])],\n    async (request, response) => {\n      try {\n        const { type } = request.params;\n        if (!validExportTypes.includes(type))\n          return response.sendStatus(400).end();\n\n        const { workspaceSlug, threadSlug } = reqBody(request);\n        const { Workspace } = require(\"../models/workspace\");\n        const { WorkspaceThread } = require(\"../models/workspaceThread\");\n        const { WorkspaceChats } = require(\"../models/workspaceChats\");\n\n        const user = await userFromSession(request, response);\n        const workspace = multiUserMode(response)\n          ? await Workspace.getWithUser(user, { slug: String(workspaceSlug) })\n          : await Workspace.get({ slug: String(workspaceSlug) });\n        if (!workspace) return response.sendStatus(404).end();\n\n        let thread;\n        if (threadSlug) {\n          thread = await WorkspaceThread.get({\n            slug: String(threadSlug),\n            user_id: user?.id || null,\n          });\n          if (!thread) return response.sendStatus(404).end();\n        }\n\n        const chats = await WorkspaceChats.where({\n          workspaceId: workspace.id,\n          user_id: user?.id || null,\n          thread_id: thread?.id || null,\n        });\n        if (chats.length === 0) return response.sendStatus(400).end();\n\n        const meta = {","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/endpoints/utils.js#L35-L71","documentation":"Returned by POST /export-chat/:type when the workspaceSlug supplied in the request body does not resolve to a workspace. In single-user mode Workspace.get({slug}) returns null; in multi-user mode Workspace.getWithUser(user,{slug}) also returns null when the user lacks membership. The 404 is an explicit resource-existence guard before the expensive chat-history query is run.","triggerScenarios":"POST /export-chat/json (or csv/jsonl) with a workspaceSlug that is misspelled, belongs to another user under multi-user mode, references a deleted workspace, or is undefined (coerced to the literal string 'undefined').","commonSituations":"Frontend cached a stale workspace slug after the workspace was renamed or deleted; multi-user mode was toggled on and the caller is no longer a member; copy-paste typo in the slug.","solutions":["Call GET /workspace/:slug first and confirm it returns 200 before issuing the export POST.","In multi-user mode, verify the authenticated user is a member of the target workspace.","Ensure the request body includes a non-empty workspaceSlug string that matches an existing workspace slug."],"exampleFix":"// before\nPOST /export-chat/json\n{ \"workspaceSlug\": \"my-workspce\" }  // typo → 404\n\n// after\nPOST /export-chat/json\n{ \"workspaceSlug\": \"my-workspace\" }","handlingStrategy":"validation","validationCode":"// Before calling POST /export-chat/:type, confirm the workspace exists:\nasync function workspaceExists(api, workspaceSlug) {\n  const res = await api.get(`/workspace/${encodeURIComponent(workspaceSlug)}`);\n  return res.status === 200 && !!res.data?.workspace;\n}\n\nif (!(await workspaceExists(api, workspaceSlug))) {\n  throw new Error(`Workspace '${workspaceSlug}' not found or inaccessible`);\n}","typeGuard":"function isValidWorkspaceSlug(slug) {\n  return typeof slug === 'string' && slug.trim().length > 0 && /^[a-z0-9-]+$/i.test(slug);\n}","tryCatchPattern":"try {\n  const res = await api.post('/export-chat/json', { workspaceSlug });\n} catch (e) {\n  if (e.response?.status === 404) {\n    // workspace not found — prompt user to select a valid workspace\n  } else { throw e; }\n}","preventionTips":["Fetch the workspace list once and populate a dropdown so users pick valid slugs.","In multi-user mode, filter the list to workspaces the user can access.","Validate the slug format client-side before making the request."],"tags":["http-404","workspace","export","slug-validation","multi-user"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}