{"record":{"id":"f8f739bb92d3c5ed","repo":"RocketChat/Rocket.Chat","slug":"message-not-found-f8f739","errorCode":null,"errorMessage":"Message not found","messagePattern":"Message not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/client/views/room/contextualBar/Threads/hooks/useGetMessageByID.ts","lineNumber":25,"sourceCode":"import { Messages } from '../../../../../stores';\n\nexport const useGetMessageByID = (shouldStoreMessage: boolean = true) => {\n\tconst getMessage = useEndpoint('GET', '/v1/chat.getMessage');\n\tconst storeMessage = Messages.use((state) => state.store);\n\n\treturn useCallback(\n\t\tasync (mid: IMessage['_id']) => {\n\t\t\ttry {\n\t\t\t\tconst { message: rawMessage } = await getMessage({ msgId: mid });\n\t\t\t\tconst mappedMessage = mapMessageFromApi(rawMessage);\n\t\t\t\tconst message = (await onClientMessageReceived(mappedMessage)) || mappedMessage;\n\t\t\t\tif (shouldStoreMessage) {\n\t\t\t\t\tstoreMessage(message);\n\t\t\t\t}\n\t\t\t\treturn message;\n\t\t\t} catch (error) {\n\t\t\t\tif (typeof error === 'object' && error !== null && 'success' in error) {\n\t\t\t\t\tthrow new Error('Message not found');\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\t[getMessage, shouldStoreMessage, storeMessage],\n\t);\n};\n","sourceCodeStart":7,"sourceCodeEnd":34,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/client/views/room/contextualBar/Threads/hooks/useGetMessageByID.ts#L7-L34","documentation":"Thrown by useGetMessageByID's callback when the getMessage API call (REST endpoint for fetching a single message) returns an error object that has a 'success' property (the Rocket.Chat REST API error shape: { success: false, error: ..., ... }). The function catches the API error and re-throws it as a generic 'Message not found' Error, masking the original error details.","triggerScenarios":"The message ID does not exist on the server. The message exists but the user lacks permission to read it. The message was deleted. The REST API returns success: false for any reason (rate limiting, server error) — the catch block treats all such errors as 'not found'.","commonSituations":"Loading a thread whose main message was deleted. User navigates to a message in a room they were removed from. Message ID from a stale link. Any API error with success: false is misreported as 'not found'.","solutions":["Verify the message exists and the user has access before fetching by ID.","Catch the 'Message not found' error in the consuming component and show appropriate UI.","Note that this catch block loses the original API error details — for debugging, inspect the network response directly.","For deleted messages, refresh the thread/room data to remove stale references."],"exampleFix":"// before\nconst message = await getMessageByID(mid);\n// after\ntry {\n  const message = await getMessageByID(mid);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Message not found') {\n    // show 'message deleted or inaccessible' UI\n    return;\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"const exists = Messages.state.get(mid);\nif (!exists) {\n  // optionally verify via API, or show 'not available'\n  return;\n}","typeGuard":"const isApiErrorResponse = (error: unknown): boolean =>\n  typeof error === 'object' && error !== null && 'success' in error;","tryCatchPattern":"try {\n  const message = await getMessageByID(mid);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Message not found') {\n    // message deleted, inaccessible, or API error\n    showMessageDeletedState();\n    return;\n  }\n  throw e;\n}","preventionTips":["Catch 'Message not found' explicitly when loading messages by ID.","Note that the original API error details are lost — inspect network responses for debugging.","Verify message existence and user permissions before fetching by ID.","Refresh thread/room data when stale message references cause this error."],"tags":["message","api-call","thread","permissions","error-masking"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}