{"record":{"id":"45f279781b938c4b","repo":"iflytek/astron-agent","slug":"response-failed-bearer-key-must-not-be-blank","errorCode":"RESPONSE_FAILED","errorMessage":"Bearer key must not be blank","messagePattern":"Bearer key must not be blank","errorType":"validation","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/handler/RpaHandler.java","lineNumber":52,"sourceCode":"    /**\n     * Get RPA workflow list from downstream API.\n     *\n     * <p>\n     * Performs parameter validation, constructs request URL, invokes HTTP call, parses the response,\n     * and returns the workflow list data.\n     * </p>\n     *\n     * @param pageNo page number (>= 1, default 1 if null)\n     * @param pageSize page size (1~1000, default 20 if null; values outside the range will be trimmed)\n     * @param key secret/token used to generate Bearer Token (must not be blank)\n     * @return {@link JSONObject} containing workflow list data\n     * @throws BusinessException if parameters are invalid, HTTP call fails, response parsing fails, or\n     *         downstream returns a non-zero code\n     */\n    public JSONObject getRpaList(Integer pageNo, Integer pageSize, String key) {\n        // 1) Validate and normalize parameters\n        if (key == null || key.isBlank()) {\n            throw new BusinessException(ResponseEnum.RESPONSE_FAILED, \"Bearer key must not be blank\");\n        }\n        int safePageNo = Math.max(1, Objects.requireNonNullElse(pageNo, 1));\n        int safePageSize = Math.min(Math.max(Objects.requireNonNullElse(pageSize, 20), 1), 1000);\n\n        final String base = apiUrl.getRpaUrl();\n        if (base == null || base.isBlank()) {\n            throw new BusinessException(ResponseEnum.RESPONSE_FAILED, \"RPA base url is not configured\");\n        }\n\n        // 2) Build request URL and headers\n        final String url = String.format(\"%s%s?pageNo=%d&pageSize=%d\", base, RPA_ROBOT_LIST, safePageNo, safePageSize);\n        final Map<String, String> headers = Map.of(\n                \"Authorization\", \"Bearer \" + key,\n                \"Accept\", \"application/json; charset=utf-8\");\n\n        log.info(\"getRpaList -> url: {}, headers: {}\", url, headers);\n\n        // 3) Call downstream API and parse response","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/handler/RpaHandler.java#L34-L70","documentation":"getRpaList validates its parameters before issuing the HTTP request; an empty or null bearer key ('key') fails fast with BusinessException(RESPONSE_FAILED, \"Bearer key must not be blank\"). This is a client-side argument validation error — no network call is made.","triggerScenarios":"Calling getRpaList with key == null, key.isBlank(), or an empty/whitespace-only bearer token string.","commonSituations":"RPA token not configured in the environment/user settings; token cleared or never stored; frontend passing an empty key after logout or config reset.","solutions":["Configure a valid non-blank RPA bearer key before calling getRpaList","Check where the key is sourced (config table/env/user input) and why it is empty","Re-obtain or regenerate the RPA token if it expired and was wiped","Add a pre-flight check in the UI to require the key before invoking RPA listing"],"exampleFix":"// before\nrpaHandler.getRpaList(pageNo, pageSize, key); // key may be blank\n// after\nif (key == null || key.isBlank()) {\n    throw new IllegalArgumentException(\"RPA bearer key is not configured\");\n}\nrpaHandler.getRpaList(pageNo, pageSize, key.trim());","handlingStrategy":"validation","validationCode":"if (key == null || key.isBlank()) {\n    throw new IllegalStateException(\"RPA bearer key is not configured\");\n}\nrpaHandler.getRpaList(pageNo, pageSize, key.trim());","typeGuard":"boolean hasBearerKey(String key) {\n    return key != null && !key.isBlank();\n}","tryCatchPattern":null,"preventionTips":["Store the RPA bearer key in configuration and fail fast at startup if missing","Trim user-supplied tokens before use","Add a UI-level check that a token exists before enabling RPA features"],"tags":["validation","java","authentication","rpa"],"backgroundTag":"empty-required-field","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}