{"record":{"id":"395d20af4569d8c9","repo":"Mintplex-Labs/anything-llm","slug":"device-not-found","errorCode":null,"errorMessage":"Device not found","messagePattern":"Device not found","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"server/endpoints/mobile/index.js","lineNumber":51,"sourceCode":"  );\n\n  /**\n   * Updates the device status via an updates object.\n   * @param {import(\"express\").Request} request\n   * @param {import(\"express\").Response} response\n   */\n  app.post(\n    \"/mobile/update/:id\",\n    [validatedRequest, flexUserRoleValid([ROLES.admin])],\n    async (request, response) => {\n      try {\n        const body = reqBody(request);\n        const updates = await MobileDevice.update(\n          Number(request.params.id),\n          body\n        );\n        if (updates.error)\n          return response.status(400).json({ error: updates.error });\n        return response.status(200).json({ updates });\n      } catch (e) {\n        console.error(e);\n        response.sendStatus(500).end();\n      }\n    }\n  );\n\n  /**\n   * Deletes a device from the database.\n   * @param {import(\"express\").Request} request\n   * @param {import(\"express\").Response} response\n   */\n  app.delete(\n    \"/mobile/:id\",\n    [validatedRequest, flexUserRoleValid([ROLES.admin])],\n    async (request, response) => {\n      try {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/mobile/index.js#L33-L69","documentation":"Returned by POST /api/mobile/update/:id (admin only). The route calls MobileDevice.update(Number(request.params.id), body), which first does MobileDevice.get({ id: parseInt(id) }); when no desktop_mobile_devices row matches (or the lookup fails and the model catch returns []), update returns { error: 'Device not found' } and the endpoint relays it as HTTP 400. It means the numeric id you passed does not identify an existing mobile device row.","triggerScenarios":"POST /api/mobile/update/<id> where <id> is a device that was already deleted via DELETE /api/mobile/:id, a non-numeric value (Number() yields NaN so Prisma finds nothing), or the device token/UUID mistakenly used in place of the numeric DB id.","commonSituations":"Admin device list is stale after another admin deleted the device; client passes the device token instead of the numeric id; id copied from a different environment/database; row deleted while an approve dialog was open.","solutions":["Re-fetch the device list with GET /api/mobile and use the numeric id field from that response","If the device was deleted, drop it from client state — no update is needed","Send the plain integer DB id in the URL (POST /api/mobile/update/3), never the token or UUID string","Check server logs: MobileDevice.get logs 'FAILED TO GET MOBILE DEVICE.' if the Prisma lookup itself errored"],"exampleFix":"// before — device token used as :id\nawait fetch(`/api/mobile/update/${device.token}`, { method: 'POST', ... });\n\n// after — numeric DB id from a fresh list call\nconst devices = await (await fetch('/api/mobile')).json();\nconst id = devices.find((d) => d.token === device.token)?.id;\nawait fetch(`/api/mobile/update/${id}`, { method: 'POST', ... });","handlingStrategy":"validation","validationCode":"const res = await fetch('/api/mobile');\nconst devices = await res.json();\nif (!devices.some((d) => d.id === Number(targetId))) {\n  throw new Error('Device no longer exists — refresh the device list');\n}","typeGuard":null,"tryCatchPattern":"try {\n  const r = await updateDevice(targetId, { approved: true });\n} catch (e) {\n  if (e.status === 400 && e.body?.error === 'Device not found') {\n    await refreshDeviceList(); // reconcile stale local state\n  } else throw e;\n}","preventionTips":["Always source the id from a fresh GET /api/mobile response","Store the numeric id, not the token, when building admin UI actions","Reconcile local lists whenever any 400 'Device not found' comes back"],"tags":["mobile","device-management","rest-api","not-found","admin"],"backgroundTag":"resource-not-found","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-08-23T16:17:53.355Z"}