{"record":{"id":"39f6ead8ea54e369","repo":"iflytek/astron-agent","slug":"convertimageerrorcodetoresponseenum-responsecode","errorCode":null,"errorMessage":"convertImageErrorCodeToResponseEnum(responseCode)","messagePattern":"convertImageErrorCodeToResponseEnum\\(responseCode\\)","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/BotAIServiceClient.java","lineNumber":165,"sourceCode":"\n                String responseBodyString = responseBody.string();\n                JSONObject result = JSONObject.parseObject(responseBodyString);\n\n                // Get error code from response\n                Integer responseCode = result.getJSONObject(\"header\").getInteger(\"code\");\n                if (responseCode == null) {\n                    responseCode = result.getIntValue(\"header.code\", -1);\n                }\n\n                log.info(\"Image generation request completed, user [{}], response code: {}\", uid, responseCode);\n\n                // Check if there is an error\n                if (responseCode != 0) {\n                    log.error(\"Image generation service returned error, user [{}], error code: {}\", uid, responseCode);\n\n                    // Convert error code to corresponding ResponseEnum and throw\n                    ResponseEnum responseEnum = convertImageErrorCodeToResponseEnum(responseCode);\n                    throw new BusinessException(responseEnum);\n                }\n\n                return result;\n            }\n        } catch (BusinessException e) {\n            // Re-throw BusinessException directly\n            throw e;\n        } catch (Exception e) {\n            log.error(\"Image generation request failed, user [{}]\", uid, e);\n            throw new BusinessException(ResponseEnum.SYSTEM_ERROR);\n        }\n    }\n\n    /**\n     * Text generation request (for opening lines generation and other functions)\n     *\n     * @param question Generation prompt\n     * @param domain Model domain","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/BotAIServiceClient.java#L147-L183","documentation":"After a successful HTTP call, generateImage() reads result.header.code from the Spark response; if it is non-zero, the service-level error code is mapped via convertImageErrorCodeToResponseEnum() and thrown as a BusinessException with the mapped ResponseEnum. This is the Spark image API's application-level error path, distinct from HTTP status errors.","triggerScenarios":"The Spark image-generation service accepted the HTTP request but returned header.code != 0 — e.g. invalid prompt/size parameters, quota/authorization limits, content moderation rejection, or internal service error, each mapped to a specific ResponseEnum.","commonSituations":"Image size outside the allowed set (validateImageSize passed but the remote rejects it); account quota exhausted; prompt blocked by content moderation; Spark API version behavior change returning new/unknown codes that map to a generic error enum.","solutions":["Log/inspect the actual Spark header.code value to find the mapped meaning and address that specific cause","Validate the image size and prompt against the current Spark image API constraints before calling","Check the platform account's quota/billing status on the iFlytek open platform if the code indicates limits","Update convertImageErrorCodeToResponseEnum mappings if the Spark API introduced new error codes"],"exampleFix":"// before\nJSONObject result = botAIServiceClient.generateImage(uid, prompt, 2048); // server-side param error\n// after\nint safeSize = Math.min(Math.max(size, 512), 2048); // per Spark API constraints\nJSONObject result = botAIServiceClient.generateImage(uid, prompt, safeSize);","handlingStrategy":"try-catch","validationCode":"Integer size = validateImageSize(requestedSize); // clamp to Spark-supported sizes before calling\nif (StrUtil.isBlank(prompt) || prompt.length() > MAX_PROMPT_LEN) {\n    throw new IllegalArgumentException(\"Prompt empty or too long for Spark image API\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    JSONObject result = botAIServiceClient.generateImage(uid, prompt, size);\n} catch (BusinessException e) {\n    log.error(\"Spark image API rejected request: {}\", e.getMessage());\n    // inspect header.code mapping (quota, moderation, params) and handle per cause\n}","preventionTips":["Validate prompt and size against current Spark image API limits before calling","Watch account quota/limits on the iFlytek open platform","Keep convertImageErrorCodeToResponseEnum mappings updated with new Spark error codes"],"tags":["spark-api","image-generation","api-error"],"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"}