{"record":{"id":"2c21a82813e96649","repo":"RocketChat/Rocket.Chat","slug":"fileupload-error","errorCode":null,"errorMessage":"FileUpload_Error","messagePattern":"FileUpload_Error","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/meteor/client/hooks/useEndpointUploadMutation.ts","lineNumber":30,"sourceCode":"\tconst sendData = useUpload(endpoint as PathFor<'POST'>);\n\tconst dispatchToastMessage = useToastMessageDispatch();\n\n\treturn useMutation({\n\t\tmutationFn: async (formData: FormData): Promise<TData> => {\n\t\t\tconst data = sendData(formData);\n\t\t\tconst promise = data instanceof Promise ? data : data.promise;\n\t\t\tconst result = await promise;\n\n\t\t\tif (!result.success) {\n\t\t\t\tif (result.status) {\n\t\t\t\t\tthrow new Error(result.status);\n\t\t\t\t}\n\n\t\t\t\tif (typeof result.error === 'string') {\n\t\t\t\t\tthrow new Error(result.error);\n\t\t\t\t}\n\n\t\t\t\tthrow new Error(t('FileUpload_Error'));\n\t\t\t}\n\t\t\treturn result as TData;\n\t\t},\n\t\tonError: (error) => {\n\t\t\tdispatchToastMessage({ type: 'error', message: error });\n\t\t},\n\t\t...options,\n\t});\n};\n","sourceCodeStart":12,"sourceCodeEnd":40,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/client/hooks/useEndpointUploadMutation.ts#L12-L40","documentation":"Thrown by the upload mutation wrapper in useEndpointUploadMutation when the awaited upload result has success === false but carries neither a result.status nor a string result.error, so no specific message can be extracted. The message is the i18n key 'FileUpload_Error', which the hook's onError renders as an error toast via dispatchToastMessage. It is the generic fallback for uploads that fail without a structured JSON error payload.","triggerScenarios":"Calling mutate/mutateAsync on a mutation built with useEndpointUploadMutation (e.g. POST /v1/rooms.upload/{rid}) when the server answers non-2xx with a non-JSON body (HTML error page, empty body, proxy error), or when the upload transport resolves with { success: false } but no status/error fields.","commonSituations":"File larger than the server's upload limit (nginx client_max_body_size or Rocket.Chat FileUpload_MaxFileSize), expired auth token yielding an HTML login redirect instead of JSON, reverse proxy or CORS interference on large multipart bodies, or a custom endpoint that returns a bare { success: false }.","solutions":["Inspect the actual upload response in the browser Network tab and fix the underlying HTTP failure (413 size limit, 401 auth, 502 proxy) first.","Validate the file client-side against FileUpload_MaxFileSize and allowed media types before calling mutate.","If you control the endpoint, return a JSON body with a status field so result.status is propagated instead of this generic message.","Wrap mutateAsync in try/catch (or rely on onError) to show a specific message or offer a retry."],"exampleFix":"// before\nconst { mutateAsync } = useEndpointUploadMutation('POST', '/v1/rooms.upload/{rid}', { promise: true });\nawait mutateAsync(file); // generic FileUpload_Error toast on failure\n\n// after\nconst maxFileSize = settings.get('FileUpload_MaxFileSize') ?? 0;\nif (maxFileSize && file.size > maxFileSize) {\n  dispatchToastMessage({ type: 'error', message: t('File_exceeds_allowed_size_of_s', { size: maxFileSize }) });\n} else {\n  await mutateAsync(file);\n}","handlingStrategy":"try-catch","validationCode":"const maxBytes = settings.get('FileUpload_MaxFileSize') ?? 0;\nif (maxBytes && file.size > maxBytes) {\n  dispatchToastMessage({ type: 'error', message: t('File_exceeds_allowed_size_of_s', { size: maxBytes }) });\n  return;\n}\n// also verify allowed media types before mutating\nawait mutateAsync(file);","typeGuard":null,"tryCatchPattern":"try {\n  const result = await mutateAsync(file);\n} catch (e) {\n  // the hook's onError already toasts; branch here for retry/telemetry\n  if (e instanceof Error) {\n    reportUploadFailure(file.name, e.message);\n  }\n}","preventionTips":["Validate file size and type against workspace settings before starting the upload.","Keep upload endpoints behind JSON-error-returning routes so result.status is populated.","Watch the Network tab when this toast appears — the generic message almost always hides a 4xx/5xx body."],"tags":["file-upload","i18n","http","react-query"],"backgroundTag":"file-upload-failed","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}