{"record":{"id":"78771ad3774821f3","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-78771a","errorCode":"error-invalid-user","errorMessage":"Invalid user","messagePattern":"Invalid user","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/platform/getStatistics.ts","lineNumber":20,"sourceCode":"import type { ServerMethods } from '@rocket.chat/ddp-client';\nimport { Meteor } from 'meteor/meteor';\n\nimport { methodDeprecationLogger } from '../../lib/deprecationWarningLogger';\nimport { getLastStatistics } from '../../lib/statistics/functions/getLastStatistics';\n\ndeclare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\tgetStatistics(refresh?: boolean): IStats;\n\t}\n}\n\nMeteor.methods<ServerMethods>({\n\tasync getStatistics(refresh) {\n\t\tmethodDeprecationLogger.method('getStatistics', '9.0.0', '/v1/statistics');\n\t\tconst uid = Meteor.userId();\n\t\tif (!uid) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getStatistics' });\n\t\t}\n\t\treturn getLastStatistics({\n\t\t\tuserId: uid,\n\t\t\trefresh,\n\t\t});\n\t},\n});\n","sourceCodeStart":2,"sourceCodeEnd":28,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/platform/getStatistics.ts#L2-L28","documentation":"Thrown by the 'getStatistics' Meteor method when there is no authenticated user. The method returns workspace statistics via getLastStatistics({ userId: uid, refresh }) and resolves the caller from Meteor.userId(); a null uid aborts before statistics are gathered. Deprecated since 9.0.0 in favor of /v1/statistics (named by its deprecation logger).","triggerScenarios":"The statistics/instance info panel loads with an expired session; monitoring scripts call the DDP method without login; a logged-out admin view still triggers the fetch.","commonSituations":"Admin dashboards polled after token expiry; automated monitoring not authenticated; 9.x migrations to GET /v1/statistics.","solutions":["Re-authenticate and retry the statistics fetch","Guard with Meteor.userId() before calling","Migrate to GET /v1/statistics with an authenticated request (deprecation already logged)","Silence the fetch entirely when no session is present"],"exampleFix":"// before\nconst stats = await Meteor.callAsync('getStatistics', refresh);\n\n// after\nif (!Meteor.userId()) {\n  return handleSessionExpired();\n}\nconst stats = await Meteor.callAsync('getStatistics', refresh);\n// 9.x+: prefer GET /v1/statistics with an authenticated request","handlingStrategy":"validation","validationCode":"// client: statistics fetch requires a session\nif (!Meteor.userId()) {\n  // skip or defer the statistics fetch\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  const stats = await Meteor.callAsync('getStatistics', refresh);\n} catch (err) {\n  if (isMeteorError(err, 'error-invalid-user')) {\n    // session expired: re-authenticate and refetch\n  } else {\n    throw err;\n  }\n}","preventionTips":["Authenticate monitoring/telemetry clients instead of calling the DDP method anonymously","Prefer GET /v1/statistics — the DDP method is deprecated in 9.0.0"],"tags":["meteor","authentication","rocket-chat","statistics","deprecated-api"],"backgroundTag":"user-not-authenticated","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}