{"record":{"id":"af72ac79c1a70787","repo":"alibaba/nacos","slug":"result-getcode","errorCode":"{result.getCode()}","errorMessage":"{remoteResultMessage}","messagePattern":"\\{remoteResultMessage\\}","errorType":"exception","errorClass":"NacosException","httpStatus":null,"severity":"error","filePath":"plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/utils/RemoteServerUtil.java","lineNumber":117,"sourceCode":"        int actual = index.getAndUpdate(operand -> (operand + 1) % serverAddresses.size());\n        return serverAddresses.get(actual);\n    }\n    \n    public static String getRemoteServerContextPath() {\n        return remoteServerContextPath;\n    }\n    \n    /**\n     * Single check http result, if not success, wrapper result as Nacos exception.\n     *\n     * @param result http execute result\n     * @throws NacosException wrapper result as NacosException\n     */\n    public static void singleCheckResult(HttpRestResult<String> result) throws NacosException {\n        if (result.ok()) {\n            return;\n        }\n        throw new NacosException(result.getCode(), result.getMessage());\n    }\n    \n    /**\n     * Build the remote server identity header from the server module configuration.\n     *\n     * @return remote server identity header\n     */\n    public static Header buildServerRemoteHeader() {\n        Header header = Header.newInstance();\n        NacosAuthConfig config = NacosAuthConfigHolder.getInstance()\n            .getNacosAuthConfigByScope(ApiType.OPEN_API.name());\n        if (config != null && StringUtils.isNotBlank(config.getServerIdentityKey())) {\n            header.addParam(config.getServerIdentityKey(), config.getServerIdentityValue());\n        }\n        return header;\n    }\n}\n","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/utils/RemoteServerUtil.java#L99-L135","documentation":"Thrown by RemoteServerUtil.singleCheckResult() when an HTTP result from a remote Nacos server call does not pass result.ok() — meaning the server returned a non-success code. This is the central error-propagation method used by all remote service operations (user management, visibility grants). It wraps the remote code and message into a NacosException that callers then catch and re-throw. The code is dynamic (result.getCode()) so it carries whatever the remote server reported.","triggerScenarios":"Any remote HTTP call (createUser, deleteUser, listUsers, grant, revoke, etc.) where the remote Nacos server returns a non-OK Result — e.g. code 403 (access denied), code 404 (not found), code 500 (server error), or any other non-zero Result code.","commonSituations":"The forwarded access token is expired or invalid; the calling user lacks the required permissions on the remote server; the remote server has an internal error; the requested resource doesn't exist; the server identity verification fails.","solutions":["Inspect the NacosException errCode — it carries the remote server's original Result code which identifies the specific failure.","For auth errors (403), verify the access token and server identity headers are correctly forwarded.","For server errors (500), check the remote server's logs for the root cause.","For not-found errors (404), verify the resource exists on the remote server before retrying."],"exampleFix":"// Handle the propagated remote error at the call site:\ntry {\n    RemoteServerUtil.singleCheckResult(result);\n} catch (NacosException e) {\n    // e.getErrCode() carries the remote server's Result code\n    // e.getErrMsg() carries the remote server's error message\n    log.warn(\"Remote operation failed: code={}, msg={}\", e.getErrCode(), e.getErrMsg());\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    RemoteServerUtil.singleCheckResult(result);\n} catch (NacosException e) {\n    // e.getErrCode() = remote Result code, e.getErrMsg() = remote error message\n    log.warn(\"Remote call failed: code={}, msg={}\", e.getErrCode(), e.getErrMsg());\n    throw e;\n}","preventionTips":["Always check result.ok() before calling singleCheckResult if you want to handle errors gracefully.","Ensure forwarded access tokens and server identity headers are valid to avoid auth-level failures.","Log the remote error code and message for debugging remote operation failures."],"tags":["auth","remote-call","error-propagation","http-result"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}