{"record":{"id":"10a01127ffc85d18","repo":"Mintplex-Labs/anything-llm","slug":"device-os-and-name-are-required","errorCode":null,"errorMessage":"Device OS and name are required","messagePattern":"Device OS and name are required","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"server/endpoints/mobile/index.js","lineNumber":134,"sourceCode":"   * Will create a new device in the database but requires approval by the user\n   * before it can be used.\n   * @param {import(\"express\").Request} request\n   * @param {import(\"express\").Response} response\n   */\n  app.post(\n    \"/mobile/register\",\n    [validRegistrationToken],\n    async (request, response) => {\n      try {\n        const body = reqBody(request);\n        const result = await MobileDevice.create({\n          deviceOs: body.deviceOs,\n          deviceName: body.deviceName,\n          userId: response.locals?.user?.id,\n        });\n\n        if (result.error)\n          return response.status(400).json({ error: result.error });\n        return response.status(200).json({\n          token: result.device.token,\n          platform: MobileDevice.platform,\n        });\n      } catch (e) {\n        console.error(e);\n        response.sendStatus(500).end();\n      }\n    }\n  );\n\n  app.post(\n    \"/mobile/send/:command\",\n    [validDeviceToken],\n    async (request, response) => {\n      try {\n        return handleMobileCommand(request, response);\n      } catch (e) {","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/mobile/index.js#L116-L152","documentation":"POST /api/mobile/register (behind validRegistrationToken) calls MobileDevice.create({ deviceOs, deviceName, userId }); the model returns { error: 'Device OS and name are required' } when either value is falsy, and the endpoint relays it as HTTP 400. Both must be present non-empty strings in the JSON body.","triggerScenarios":"Registering with a body like {\"deviceOs\":\"android\"} (no deviceName), {\"deviceName\":\"Pixel\"} (no deviceOs), empty strings, or a body sent without Content-Type: application/json so reqBody parses nothing.","commonSituations":"Mobile build where the OS reports a blank device name on some devices; UI marking deviceName optional but API requiring it; multipart/form-data instead of JSON.","solutions":["Send both fields: {\"deviceOs\":\"android\",\"deviceName\":\"My Phone\"}","Ensure Content-Type: application/json and that the body is JSON.stringify'd","Default the name client-side when the platform reports it blank (e.g. fallback 'Android device')"],"exampleFix":"// before\nconst body = { deviceOs: 'android' };\n\n// after\nconst body = {\n  deviceOs: 'android',\n  deviceName: Device.deviceName || 'Android device',\n};","handlingStrategy":"validation","validationCode":"function validRegisterBody(b) {\n  return Boolean(b?.deviceOs) && Boolean(b?.deviceName);\n}\nif (!validRegisterBody(body)) throw new Error('deviceOs and deviceName are required');","typeGuard":"/** @param {any} b */\nfunction isRegisterBody(b) {\n  return (\n    typeof b?.deviceOs === 'string' && b.deviceOs.length > 0 &&\n    typeof b?.deviceName === 'string' && b.deviceName.length > 0\n  );\n}","tryCatchPattern":null,"preventionTips":["Validate both fields client-side before hitting /mobile/register","Fall back to a default device name when the OS reports a blank one","Always send JSON with Content-Type: application/json"],"tags":["mobile","registration","validation","request-body","required-field"],"backgroundTag":"missing-required-field","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-08-23T13:39:53.451Z"}