{"record":{"id":"c6f732c629304012","repo":"iflytek/astron-agent","slug":"response-failed-c6f732","errorCode":"RESPONSE_FAILED","errorMessage":"RESPONSE_FAILED","messagePattern":"RESPONSE_FAILED","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/tool/spark/SparkApiTool.java","lineNumber":256,"sourceCode":"\n        // Authentication and encryption\n        String signedSparkUrl = HttpAuthTool.assembleRequestUrl(\n                sparkMaxUrl, HttpMethod.GET.name(), config.getPlatformApiKey(), config.getPlatformApiSecret());\n        Request request = (new Request.Builder()).url(signedSparkUrl).build();\n        WebSocket webSocket = OkHttpUtil.getHttpClient().newWebSocket(request, new WebSocketListener() {\n            @Override\n            public void onOpen(@NotNull WebSocket webSocket, @NotNull Response response) {\n                log.info(\"onceChatReturnStream spark api link open\");\n            }\n\n            @Override\n            public void onMessage(@NotNull WebSocket webSocket, @NotNull String text) {\n                log.info(\"onceChatReturnStream spark api receive message:{}\", text);\n\n                SparkApiProtocol responseDto = JSON.parseObject(text, SparkApiProtocol.class);\n                if (responseDto.getHeader().getCode() != 0) {\n                    sseEmitter.complete();\n                    throw new BusinessException(ResponseEnum.RESPONSE_FAILED, text);\n                }\n\n                try {\n                    sseEmitter.send(text);\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n\n                if (responseDto.getHeader().getStatus() == 2) {\n                    sseEmitter.complete();\n                    onClosing(webSocket, 1000, \"onceChatReturnStream status=2 over\");\n                    onClosed(webSocket, 1000, \"onceChatReturnStream status=2 over\");\n                }\n            }\n\n            @Override\n            public void onMessage(@NotNull WebSocket webSocket, @NotNull ByteString bytes) {\n                log.info(\"onceChatReturnStream spark api receive message(ByteString): {}\", bytes);","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/tool/spark/SparkApiTool.java#L238-L274","documentation":"RESPONSE_FAILED is thrown by the iFlytek Spark API WebSocket handler when the platform returns a message whose header.code is non-zero, meaning Spark rejected or failed the chat request. The raw response text is attached as the exception message. It signals an upstream model-API failure, not a local bug.","triggerScenarios":"WebSocket onMessage parses a SparkApiProtocol frame and responseDto.getHeader().getCode() != 0 after calling onceChatReturnStream(content) via the signed Spark WebSocket URL.","commonSituations":"Invalid/expired iFlytek APIKey or APISecret, wrong appId in MessageBuilder.buildSparkApiRequest, exhausted model quota or concurrency limit, unsupported domain/model name, or malformed request content rejected by Spark.","solutions":["Inspect the logged response text (attached to the exception) for Spark's numeric header.code and message to identify the exact rejection reason","Verify the iFlytek open-platform appId/apiKey/apiSecret configured in platformAccountService are valid and active","Check Spark quota, concurrency limits and billing for the account","Confirm the request domain/model matches the API version the credentials are authorized for","Handle the BusinessException at the SSE caller level and surface a user-friendly message instead of breaking the stream"],"exampleFix":"// before\nif (responseDto.getHeader().getCode() != 0) {\n    sseEmitter.complete();\n    throw new BusinessException(ResponseEnum.RESPONSE_FAILED, text);\n}\n// after\nif (responseDto.getHeader().getCode() != 0) {\n    log.error(\"spark api error code={}, text={}\", responseDto.getHeader().getCode(), text);\n    sseEmitter.completeWithError(new BusinessException(ResponseEnum.RESPONSE_FAILED, text));\n    webSocket.close(1000, \"spark error\");\n    return;\n}","handlingStrategy":"try-catch","validationCode":"// Before sending, validate Spark credentials are configured\nPlatformAccountConfigDto.IflytekOpenPlatformConfig cfg = platformAccountService.requireIflytekOpenPlatform();\nif (cfg == null || isBlank(cfg.getPlatformAppId()) || isBlank(cfg.getPlatformApiKey()) || isBlank(cfg.getPlatformApiSecret())) {\n    throw new IllegalStateException(\"Spark platform credentials not configured\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    sseEmitter = sparkApiTool.onceChatReturnStream(content);\n} catch (BusinessException e) {\n    if (\"RESPONSE_FAILED\".equals(e.getCode())) {\n        log.error(\"Spark rejected request: {}\", e.getMessage());\n        sseEmitter.completeWithError(e); // or emit an SSE error event to the client\n    } else {\n        throw e;\n    }\n}","preventionTips":["Rotate and validate iFlytek appId/apiKey/apiSecret before deployment","Monitor Spark quota and concurrency limits","Log full response text on non-zero header.code to diagnose rejection reasons","Add a health check that performs a tiny Spark request at startup"],"tags":["websocket","upstream-api","spark","streaming"],"backgroundTag":"upstream-api-error","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"}