{"record":{"id":"809a47d039fffbc0","repo":"RocketChat/Rocket.Chat","slug":"error-updating-custom-user-status","errorCode":"error-updating-custom-user-status","errorMessage":"Error updating custom user status","messagePattern":"Error updating custom user status","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/api/v1/custom-user-status.ts","lineNumber":269,"sourceCode":"\t\tconst userStatusData = {\n\t\t\t_id: this.bodyParams._id,\n\t\t\tname: this.bodyParams.name,\n\t\t\tstatusType: this.bodyParams.statusType || '',\n\t\t};\n\n\t\tconst customUserStatusToUpdate = await CustomUserStatus.findOneById(userStatusData._id);\n\n\t\t// Ensure the message exists\n\t\tif (!customUserStatusToUpdate) {\n\t\t\treturn API.v1.failure(`No custom user status found with the id of \"${userStatusData._id}\".`);\n\t\t}\n\n\t\tawait insertOrUpdateUserStatus(this.userId, userStatusData);\n\n\t\tconst customUserStatus = await CustomUserStatus.findOneById(userStatusData._id);\n\n\t\tif (!customUserStatus) {\n\t\t\tthrow new Meteor.Error('error-updating-custom-user-status', 'Error updating custom user status');\n\t\t}\n\n\t\treturn API.v1.success({\n\t\t\tcustomUserStatus,\n\t\t});\n\t},\n);\n\nexport type CustomUserStatusEndpoints = ExtractRoutesFromAPI<typeof customUserStatusEndpoints>;\n\ndeclare module '@rocket.chat/rest-typings' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface\n\tinterface Endpoints extends CustomUserStatusEndpoints {}\n}\n","sourceCodeStart":251,"sourceCodeEnd":284,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/server/api/v1/custom-user-status.ts#L251-L284","documentation":"Thrown by POST custom-user-status.update after insertOrUpdateUserStatus completed but CustomUserStatus.findOneById(_id) returns null. The record disappeared between the update and the re-fetch. Note the earlier 'no custom user status found' case is returned as API.v1.failure, whereas this post-update miss throws — so the throw specifically signals a race or vanishing record mid-request.","triggerScenarios":"Another admin/process deletes the status between the update call and the re-read; _id invalidated mid-flight; insertOrUpdateUserStatus deleted-then-failed.","commonSituations":"Two admins editing/deleting the same status concurrently; stale _id held by the client.","solutions":["Retry the update after confirming the status still exists.","Guard against concurrent deletes (lock the UI row while editing).","Reload the status list to obtain a fresh _id before re-submitting."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// confirm the row still exists right before updating\nconst current = await CustomUserStatus.findOneById(_id);\nif (!current) { /* abort update */ }","typeGuard":null,"tryCatchPattern":"try { await updateCustomUserStatus({ _id, name, statusType }); }\ncatch (e) {\n  if (isApiError(e, 'error-updating-custom-user-status')) { /* reload list, retry once */) }\n  else throw e;\n}","preventionTips":["Lock the UI row while editing to avoid concurrent deletes.","Reload the status list after a failure to obtain a fresh _id.","Distinguish the API.v1.failure 'no status found' path from this thrown path."],"tags":["custom-user-status","rest-api","data-integrity","concurrency"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}