RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-account

error-invalid-account

Error message

Invalid WebDAV Account

What it means

The same existence-plus-ownership guard as getWebdavFileList, but inside getWebdavFilePreview: WebdavAccounts.findOneByIdAndUserId(accountId, userId, {}) returned null. It is reached only after the user check and both settings checks passed, so the failure is specifically the accountId/user pair not resolving to a stored WebDAV account.

Source

Thrown at apps/meteor/server/bridges/webdav/methods/getWebdavFilePreview.ts:35

Meteor.methods<ServerMethods>({
	async getWebdavFilePreview(accountId, path) {
		const userId = Meteor.userId();

		if (!userId) {
			throw new Meteor.Error('error-invalid-user', 'Invalid User', {
				method: 'getWebdavFilePreview',
			});
		}

		if (!settings.get('Webdav_Integration_Enabled') || !settings.get('Accounts_OAuth_Nextcloud_URL')) {
			throw new Meteor.Error('error-not-allowed', 'WebDAV Integration Not Allowed', {
				method: 'getWebdavFilePreview',
			});
		}

		const account = await WebdavAccounts.findOneByIdAndUserId(accountId, userId, {});
		if (!account) {
			throw new Meteor.Error('error-invalid-account', 'Invalid WebDAV Account', {
				method: 'getWebdavFilePreview',
			});
		}

		try {
			const cred = getWebdavCredentials(account);
			const client = createClient(account.serverURL, cred);
			const serverURL = settings.get('Accounts_OAuth_Nextcloud_URL');
			const res = await client.customRequest(`${serverURL}/index.php/core/preview.png?file=${path}&x=64&y=64`, {
				method: 'GET',
				responseType: 'arraybuffer',
			});
			return { success: true, data: res.data as ArrayBuffer };
		} catch (error) {
			// ignore error
		}
	},
});

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Re-authorize the WebDAV account and use the new accountId
  2. Refresh the account list before rendering the preview action
  3. Validate that the accountId belongs to the logged-in user before calling
Defensive patterns

Strategy: validation

Validate before calling

const accounts = await getWebdavAccountsForUser(); // e.g. via the accounts subscription/endpoint
if (!accounts.some((a) => a._id === accountId)) {
  // refresh accounts / prompt re-authorization instead of requesting the preview
}

Try / catch

try {
  const { data } = await Meteor.callAsync('getWebdavFilePreview', accountId, path);
} catch (e: any) {
  if (e?.error === 'error-invalid-account') {
    // re-sync account list, then let the user retry from a valid account
  }
}

Prevention

When it happens

Trigger: Requesting a preview with a deleted, re-created, or cross-user accountId; accountId undefined after a client-side state reset; account removed between listing files and clicking one for preview.

Common situations: Stale accountId in component state after the user re-authorized Nextcloud; race where an admin removed the account while the user browsed files; URL-parameter-driven UI receiving a bogus accountId.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/89879e868cb962d8. Report an issue: GitHub.