{"record":{"id":"d8b70918f0d89fe6","repo":"languagetool-org/languagetool","slug":"could-not-fetch-user-information","errorCode":null,"errorMessage":"Could not fetch user information","messagePattern":"Could not fetch user information","errorType":"http","errorClass":"IllegalStateException","httpStatus":500,"severity":"error","filePath":"languagetool-server/src/main/java/org/languagetool/server/ApiV2.java","lineNumber":395,"sourceCode":"      } else if (authParameter.equals(\"addonToken\")) {\n        userInfo = DatabaseAccess.getInstance().getUserInfoWithAddonToken(user, password);\n      } else if (authParameter.equals(\"apiKey\")) {\n        userInfo = DatabaseAccess.getInstance().getUserInfoWithApiKey(user, password);\n      }\n\n      String format = parameters.getOrDefault(\"format\", \"extended\");\n      if (userInfo != null) {\n        if (format.equals(\"minimal\")) {\n          StringWriter sw = new StringWriter();\n          new ObjectMapper().writeValue(sw, userInfo);\n          sendJson(httpExchange, sw);\n        } else {\n          StringWriter sw = new StringWriter();\n          new ObjectMapper().writeValue(sw, DatabaseAccess.getInstance().getExtendedUserInfo(user));\n          sendJson(httpExchange, sw);\n        }\n      } else {\n        throw new IllegalStateException(\"Could not fetch user information\");\n      }\n    }\n  }\n\n  private void ensureGetMethod(HttpExchange httpExchange, String url) {\n    if (!httpExchange.getRequestMethod().equalsIgnoreCase(\"get\")) {\n      throw new BadRequestException(url + \" needs to be called with GET\");\n    }\n  }\n  \n  private void ensurePostMethod(HttpExchange httpExchange, String url) {\n    if (!httpExchange.getRequestMethod().equalsIgnoreCase(\"post\")) {\n      throw new BadRequestException(url + \" needs to be called with POST\");\n    }\n  }\n\n  @NotNull\n  private UserLimits getUserLimits(Map<String, String> parameters, HTTPServerConfig config) {","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-server/src/main/java/org/languagetool/server/ApiV2.java#L377-L413","documentation":"Inside handleGetUserInfoRequest, after authentication and premium-status checks, the handler reaches an else branch where it cannot determine which user information variant to return and throws an IllegalStateException('Could not fetch user information'). This is an internal guard for an unexpected request-state combination (e.g. an unrecognized 'authMethod' handling path or server-side user data problem), not a client-input validation error.","triggerScenarios":"A request whose authentication outcome leaves the handler in an unhandled branch (e.g. premium-with-apiKey flows not matching the coded cases); server-side state where DatabaseAccess cannot resolve the user after the auth path was accepted.","commonSituations":"Custom or forked server builds where new authMethod values were added client-side but not server-side; database connectivity or migration issues leaving extended user info unresolvable.","solutions":["Retry with the default authMethod (omit the parameter) to take the standard password path.","Check server logs for a preceding DatabaseAccess error indicating why user info could not be resolved.","Verify client and server versions match so the authMethod values your client sends are handled by the server.","If persistent, report it — this is an internal-state error rather than a request you can reshape."],"exampleFix":"// before\nGET /v2/users/me?authMethod=customMethod\n// after\nGET /v2/users/me","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// HTTP 500 from an internal-state branch\ntry {\n  const res = await fetch(usersMeUrl, { headers });\n  if (res.status === 500) throw new Error('Server could not fetch user information; check server logs and authMethod support');\n  return res.json();\n} catch (e) { /* surface or retry with default authMethod */ }","preventionTips":["Use only authMethod values the server version supports; default (omit) is safest.","Keep client and server LanguageTool versions aligned.","Monitor server logs for DatabaseAccess errors when this occurs."],"tags":["http","rest-api","internal-state","languagetool"],"backgroundTag":"internal-invariant-violation","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}