{"record":{"id":"c054ab995ac1e400","repo":"theonedev/onedev","slug":"not-authenticated","errorCode":null,"errorMessage":"Not authenticated","messagePattern":"Not authenticated","errorType":"http","errorClass":"UnauthenticatedException","httpStatus":401,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/ai/TodResource.java","lineNumber":1325,"sourceCode":"        var request = pullRequestService.find(requestReference.getProject(), requestReference.getNumber());\n        if (request != null) {\n            if (!SecurityUtils.canReadCode(request.getProject()))\n                throw new UnauthorizedException(\"No permission to access pull request: \" + referenceString);\n            return request;\n        } else {\n            throw new NotFoundException(\"Pull request not found: \" + referenceString);\n        }\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    @Path(\"/edit-pull-request\")\n    @POST\n    public Map<String, Object> editPullRequest(\n                @QueryParam(\"currentProject\") @NotNull String currentProjectPath,\n                @QueryParam(\"reference\") @NotNull String pullRequestReference, @NotNull Map<String, Serializable> data) {\n        var user = SecurityUtils.getUser();\n        if (user == null)\n            throw new UnauthenticatedException();\n\n        var currentProject = getProject(currentProjectPath);\n\n        var request = getPullRequest(currentProject, pullRequestReference);\n\n        if (!SecurityUtils.canModifyPullRequest(request))\n            throw new UnauthorizedException(\"No permission to edit pull request: \" + pullRequestReference);\n\n        normalizePullRequestData(data);\n\n        var title = (String) data.remove(\"title\");\n        if (title != null) \n            pullRequestChangeService.changeTitle(user, request, title);\n\n        if (data.containsKey(\"description\")) \n            pullRequestChangeService.changeDescription(user, request, (String) data.remove(\"description\"));\n\n        var labelNames = (List<String>) data.remove(\"labels\");","sourceCodeStart":1307,"sourceCodeEnd":1343,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/ai/TodResource.java#L1307-L1343","documentation":"The editPullRequest endpoint first calls SecurityUtils.getUser(); if there is no authenticated user in the current session/context, it throws OneDev's UnauthenticatedException (mapped to HTTP 401). The endpoint requires an authenticated identity before any project or permission checks.","triggerScenarios":"POST to the edit-pull-request endpoint without valid authentication — e.g. no session cookie, missing/expired API token, or anonymous access to the AI TOD REST resource.","commonSituations":"Missing Authorization header when calling the REST API; expired or revoked access token; calling from a script without SSO login; cookie lost after server restart.","solutions":["Send valid credentials (login session or API access token) with the request.","Generate a new access token in user profile > access tokens if the old one expired.","Log in to OneDev in the client session before invoking the endpoint."],"exampleFix":"// before\ncurl -X POST 'https://onedev/api/tod/edit-pull-request?...'\n// after\ncurl -X POST -H \"Authorization: Bearer <access-token>\" 'https://onedev/api/tod/edit-pull-request?...'","handlingStrategy":"try-catch","validationCode":"if (SecurityUtils.getUser() == null)\n    throw new IllegalStateException(\"Authentication required before calling the TOD endpoint\");","typeGuard":null,"tryCatchPattern":"try {\n    callEditEndpoint(params);\n} catch (UnauthenticatedException e) {\n    // refresh credentials / obtain a new access token, then retry once\n}","preventionTips":["Always attach an Authorization header or a valid session when calling REST endpoints.","Rotate access tokens before expiry in CI/automation.","Handle 401 globally in your API client by re-authenticating."],"tags":["authentication","rest-api","http-401","onedev"],"backgroundTag":"authentication-required","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}