{"record":{"id":"1a3bef2fcfdba31a","repo":"Mintplex-Labs/anything-llm","slug":"bad-request-1a3bef","errorCode":null,"errorMessage":"Bad Request","messagePattern":"Bad Request","errorType":"http","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"server/endpoints/utils.js","lineNumber":42,"sourceCode":"        vectorDB: process.env.VECTOR_DB || \"lancedb\",\n        storage: await getDiskStorage(),\n        appVersion: getDeploymentVersion(),\n      };\n      response.status(200).json(metrics);\n    } catch (e) {\n      console.error(e);\n      response.sendStatus(500).end();\n    }\n  });\n\n  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          });","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/endpoints/utils.js#L24-L60","documentation":"Returned by POST /export-chat/:type when the `:type` URL parameter is not in the validExportTypes list. Line 41-42 checks `if (!validExportTypes.includes(type)) return response.sendStatus(400).end()`. The valid types are defined in server/utils/chats/exportChatToFile.js line 8 as ['pdf', 'markdown', 'plaintext', 'json', 'html']. Any other value — including common variants like 'csv', 'txt', 'JSON', 'JSONL' — is rejected. The check is case-sensitive.","triggerScenarios":"The :type path parameter is a value not in the allowed list: 'csv', 'txt', 'jsonl', 'JSON' (uppercase), 'PDF' (uppercase), or a typo like 'makrdown'. The frontend export menu sends a type identifier that doesn't match the backend's constant.","commonSituations":"Frontend and backend are out of sync — the frontend offers a format (e.g., 'csv') that the backend doesn't support. Case mismatch: client sends 'JSON' but the backend expects lowercase 'json'. A typo in the type string. URL construction bug that mangles the type segment.","solutions":["Ensure the :type parameter is exactly one of: 'pdf', 'markdown', 'plaintext', 'json', 'html' (all lowercase).","Check the frontend export component for the list of types it sends and align it with the backend's validExportTypes constant.","If case insensitivity is desired, normalize the type to lowercase before validation (requires a backend code change).","Inspect the actual request URL in the network tab to confirm the type value being sent."],"exampleFix":"// before — wrong/case-mismatch type\nawait fetch('/export-chat/JSON', { method: 'POST', body: JSON.stringify({ workspaceSlug }) });\n\n// after — lowercase, valid type\nconst VALID_TYPES = ['pdf', 'markdown', 'plaintext', 'json', 'html'];\nconst type = String(userChoice).toLowerCase();\nif (!VALID_TYPES.includes(type)) throw new Error(`Invalid export type: ${type}`);\nawait fetch(`/export-chat/${type}`, { method: 'POST', body: JSON.stringify({ workspaceSlug }) });","handlingStrategy":"validation","validationCode":"const VALID_EXPORT_TYPES = ['pdf', 'markdown', 'plaintext', 'json', 'html'];\n\nfunction validateExportType(type) {\n  const normalized = String(type).toLowerCase();\n  if (!VALID_EXPORT_TYPES.includes(normalized)) {\n    throw new Error(\n      `Invalid export type '${type}'. Must be one of: ${VALID_EXPORT_TYPES.join(', ')}`\n    );\n  }\n  return normalized;\n}\n\n// Usage\nconst type = validateExportType(userSelectedType);\nawait fetch(`/export-chat/${type}`, { method: 'POST', body: JSON.stringify({ workspaceSlug }) });","typeGuard":"function isValidExportType(type) {\n  const VALID = ['pdf', 'markdown', 'plaintext', 'json', 'html'];\n  return typeof type === 'string' && VALID.includes(type.toLowerCase());\n}","tryCatchPattern":null,"preventionTips":["Always validate the export type against the allowed list before constructing the URL.","Normalize the type to lowercase client-side to avoid case-sensitivity issues.","Keep the frontend's export type list in sync with the backend's validExportTypes constant.","Watch for typos like 'makrdown' or 'pdf ' (trailing space)."],"tags":["export","validation","input-validation","bad-request","chat-export"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}