{"record":{"id":"d551a4d648db8be0","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-account-d551a4","errorCode":"error-invalid-account","errorMessage":"Invalid WebDAV Account","messagePattern":"Invalid WebDAV Account","errorType":"error_code","errorClass":"MeteorError","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/bridges/webdav/methods/uploadFileToWebdav.ts","lineNumber":43,"sourceCode":"\tasync uploadFileToWebdav(accountId, fileData, name) {\n\t\tif (!Meteor.userId()) {\n\t\t\tthrow new MeteorError('error-invalid-user', 'Invalid User', {\n\t\t\t\tmethod: 'uploadFileToWebdav',\n\t\t\t});\n\t\t}\n\n\t\tif (!settings.get('Webdav_Integration_Enabled')) {\n\t\t\tthrow new MeteorError('error-not-allowed', 'WebDAV Integration Not Allowed', {\n\t\t\t\tmethod: 'uploadFileToWebdav',\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\tawait uploadFileToWebdav(accountId, fileData instanceof ArrayBuffer ? Buffer.from(fileData) : fileData, name);\n\t\t\treturn { success: true };\n\t\t} catch (err: any) {\n\t\t\tif (typeof err === 'object' && err instanceof Error && err.name === 'error-invalid-account') {\n\t\t\t\tthrow new MeteorError(err.name, 'Invalid WebDAV Account', {\n\t\t\t\t\tmethod: 'uploadFileToWebdav',\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlogger.error({ err });\n\n\t\t\tif (err.response) {\n\t\t\t\tconst { status } = err.response;\n\t\t\t\tif (status === 404) {\n\t\t\t\t\treturn { success: false, message: 'webdav-server-not-found' };\n\t\t\t\t}\n\t\t\t\tif (status === 401) {\n\t\t\t\t\treturn { success: false, message: 'error-invalid-account' };\n\t\t\t\t}\n\t\t\t\tif (status === 412) {\n\t\t\t\t\treturn { success: false, message: 'Duplicate_file_name_found' };\n\t\t\t\t}\n\t\t\t}","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/bridges/webdav/methods/uploadFileToWebdav.ts#L25-L61","documentation":"Different from the other error-invalid-account throws: uploadFileToWebdav delegates to the server-side uploadFileToWebdav(accountId, data, name) helper, and this is the re-wrap branch — the helper threw an Error whose name is 'error-invalid-account' (its own account lookup for the user failed). The method converts it into a MeteorError with the method name attached. So the account check happened inside the helper, after the user and settings guards already passed.","triggerScenarios":"Uploading with a deleted, re-created, or cross-user accountId; the stored WebDAV account was removed between selecting the destination and completing the upload; accountId never set in the calling code.","commonSituations":"Stale accountId from client state after re-authorization; admin-removed accounts; state bugs where the accountId prop is optional and passed as undefined.","solutions":["Re-authorize the WebDAV account and upload again with the fresh accountId","Validate the accountId against the user's current account list before initiating the upload","If the account was removed on purpose, remove the upload destination from the UI"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const accounts = await getWebdavAccountsForUser();\nif (!accounts.some((a) => a._id === accountId)) {\n  throw new Error('WebDAV account is no longer available; re-authorize');\n}\nawait Meteor.callAsync('uploadFileToWebdav', accountId, fileBuffer, name);","typeGuard":null,"tryCatchPattern":"try {\n  const res = await Meteor.callAsync('uploadFileToWebdav', accountId, fileBuffer, name);\n} catch (e: any) {\n  if (e?.error === 'error-invalid-account') {\n    // prompt re-authorization; note err.name check upstream means only that name maps here\n  } else if (res === undefined) {\n    // method returns { success:false, message } for 404/401 — handle those too\n  }\n}","preventionTips":["Validate the destination account immediately before starting the upload, not when the dialog first opened","Remember this method also returns soft failures (webdav-server-not-found, 401) as { success:false } — check both the throw and the return value"],"tags":["webdav","meteor-methods","upload","account-ownership"],"backgroundTag":"resource-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}