{"record":{"id":"841d8ad2b52855ae","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-payload","errorCode":"error-invalid-payload","errorMessage":"Token is required.","messagePattern":"Token is required\\.","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/platform/cloud.ts","lineNumber":133,"sourceCode":"\t\tmethodDeprecationLogger.method('cloud:connectWorkspace', '9.0.0', '/v1/cloud.connectWorkspace');\n\t\tcheck(token, String);\n\n\t\tconst uid = Meteor.userId();\n\n\t\tif (!uid) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\t\tmethod: 'cloud:connectWorkspace',\n\t\t\t});\n\t\t}\n\n\t\tif (!(await hasPermissionAsync(uid, 'manage-cloud'))) {\n\t\t\tthrow new Meteor.Error('error-not-authorized', 'Not authorized', {\n\t\t\t\tmethod: 'cloud:connectWorkspace',\n\t\t\t});\n\t\t}\n\n\t\tif (!token) {\n\t\t\tthrow new Meteor.Error('error-invalid-payload', 'Token is required.', {\n\t\t\t\tmethod: 'cloud:connectWorkspace',\n\t\t\t});\n\t\t}\n\n\t\treturn connectWorkspace(token);\n\t},\n\t// Currently unused but will link local account to Rocket.Chat Cloud account.\n\tasync 'cloud:getOAuthAuthorizationUrl'() {\n\t\tconst uid = Meteor.userId();\n\t\tif (!uid) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\t\tmethod: 'cloud:getOAuthAuthorizationUrl',\n\t\t\t});\n\t\t}\n\n\t\tif (!(await hasPermissionAsync(uid, 'manage-cloud'))) {\n\t\t\tthrow new Meteor.Error('error-not-authorized', 'Not authorized', {\n\t\t\t\tmethod: 'cloud:getOAuthAuthorizationUrl',","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/platform/cloud.ts#L115-L151","documentation":"Thrown by 'cloud:connectWorkspace' when the token argument is an empty string. The preceding check(token, String) only enforces the type, so '' passes validation; the explicit `if (!token)` guard then rejects it with error-invalid-payload. A missing or non-string argument fails earlier inside check() with a Match.Error, so this specific error means the token was present but empty.","triggerScenarios":"Submitting the Cloud connect form with an empty token field; passing a variable that defaulted to '' (unset env var or empty setting); a copy/paste mistake that yields an empty string.","commonSituations":"Registration flow started before a token was generated on cloud.rocket.chat; automation reading the token from an unset environment variable; a UI bug sending the form before token state is bound to the input.","solutions":["Generate the workspace token in the Rocket.Chat Cloud console and paste the full non-empty value","Validate token.trim().length > 0 in the caller before invoking the method","Verify the setting or env var that supplies the token is set at read time","On error, keep the form open and prompt for the token instead of retrying with ''"],"exampleFix":"// before\nawait Meteor.callAsync('cloud:connectWorkspace', token); // token === ''\n\n// after\nif (typeof token !== 'string' || token.trim().length === 0) {\n  throw new Error('Cloud registration token is required');\n}\nawait Meteor.callAsync('cloud:connectWorkspace', token);","handlingStrategy":"validation","validationCode":"const connectWorkspace = async (token: string): Promise<void> => {\n  if (typeof token !== 'string' || token.trim().length === 0) {\n    throw new Error('Cloud registration token is required');\n  }\n  await Meteor.callAsync('cloud:connectWorkspace', token);\n};","typeGuard":"import { Meteor } from 'meteor/meteor';\n\nconst isMeteorError = (err: unknown, code?: string): err is Meteor.Error =>\n  err instanceof Meteor.Error && (code === undefined || err.error === code);","tryCatchPattern":"try {\n  await Meteor.callAsync('cloud:connectWorkspace', token);\n} catch (err) {\n  if (isMeteorError(err, 'error-invalid-payload')) {\n    // token was empty: keep the form open and prompt for it\n  } else {\n    throw err;\n  }\n}","preventionTips":["Validate required string arguments are non-empty before calling methods — check(x, String) accepts ''","Bind form submit handlers only when token state is populated","When sourcing tokens from settings or env vars, fail loudly on empty values"],"tags":["meteor","validation","rocket-chat","cloud","token"],"backgroundTag":"missing-required-parameter","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}