Mintplex-Labs/anything-llm · error
Device not found
Error message
Device not found
What it means
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.
Source
Thrown at server/endpoints/mobile/index.js:51
);
/**
* Updates the device status via an updates object.
* @param {import("express").Request} request
* @param {import("express").Response} response
*/
app.post(
"/mobile/update/:id",
[validatedRequest, flexUserRoleValid([ROLES.admin])],
async (request, response) => {
try {
const body = reqBody(request);
const updates = await MobileDevice.update(
Number(request.params.id),
body
);
if (updates.error)
return response.status(400).json({ error: updates.error });
return response.status(200).json({ updates });
} catch (e) {
console.error(e);
response.sendStatus(500).end();
}
}
);
/**
* Deletes a device from the database.
* @param {import("express").Request} request
* @param {import("express").Response} response
*/
app.delete(
"/mobile/:id",
[validatedRequest, flexUserRoleValid([ROLES.admin])],
async (request, response) => {
try {View on GitHub (pinned to 3aec848f28)
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
Example fix
// before — device token used as :id
await fetch(`/api/mobile/update/${device.token}`, { method: 'POST', ... });
// after — numeric DB id from a fresh list call
const devices = await (await fetch('/api/mobile')).json();
const id = devices.find((d) => d.token === device.token)?.id;
await fetch(`/api/mobile/update/${id}`, { method: 'POST', ... }); Defensive patterns
Strategy: validation
Validate before calling
const res = await fetch('/api/mobile');
const devices = await res.json();
if (!devices.some((d) => d.id === Number(targetId))) {
throw new Error('Device no longer exists — refresh the device list');
} Try / catch
try {
const r = await updateDevice(targetId, { approved: true });
} catch (e) {
if (e.status === 400 && e.body?.error === 'Device not found') {
await refreshDeviceList(); // reconcile stale local state
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/395d20af4569d8c9.
Report an issue: GitHub.