iflytek/astron-agent · error · BusinessException

convertImageErrorCodeToResponseEnum(responseCode)

Error message

convertImageErrorCodeToResponseEnum(responseCode)

What it means

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.

Solutions

  1. Log/inspect the actual Spark header.code value to find the mapped meaning and address that specific cause
  2. Validate the image size and prompt against the current Spark image API constraints before calling
  3. Check the platform account's quota/billing status on the iFlytek open platform if the code indicates limits
  4. Update convertImageErrorCodeToResponseEnum mappings if the Spark API introduced new error codes

Example fix

// before
JSONObject result = botAIServiceClient.generateImage(uid, prompt, 2048); // server-side param error
// after
int safeSize = Math.min(Math.max(size, 512), 2048); // per Spark API constraints
JSONObject result = botAIServiceClient.generateImage(uid, prompt, safeSize);
Defensive patterns

Strategy: try-catch

Validate before calling

Integer size = validateImageSize(requestedSize); // clamp to Spark-supported sizes before calling
if (StrUtil.isBlank(prompt) || prompt.length() > MAX_PROMPT_LEN) {
    throw new IllegalArgumentException("Prompt empty or too long for Spark image API");
}

Try / catch

try {
    JSONObject result = botAIServiceClient.generateImage(uid, prompt, size);
} catch (BusinessException e) {
    log.error("Spark image API rejected request: {}", e.getMessage());
    // inspect header.code mapping (quota, moderation, params) and handle per cause
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/39f6ead8ea54e369. Report an issue: GitHub.

Appendix: source

Thrown at console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/BotAIServiceClient.java:165

                String responseBodyString = responseBody.string();
                JSONObject result = JSONObject.parseObject(responseBodyString);

                // Get error code from response
                Integer responseCode = result.getJSONObject("header").getInteger("code");
                if (responseCode == null) {
                    responseCode = result.getIntValue("header.code", -1);
                }

                log.info("Image generation request completed, user [{}], response code: {}", uid, responseCode);

                // Check if there is an error
                if (responseCode != 0) {
                    log.error("Image generation service returned error, user [{}], error code: {}", uid, responseCode);

                    // Convert error code to corresponding ResponseEnum and throw
                    ResponseEnum responseEnum = convertImageErrorCodeToResponseEnum(responseCode);
                    throw new BusinessException(responseEnum);
                }

                return result;
            }
        } catch (BusinessException e) {
            // Re-throw BusinessException directly
            throw e;
        } catch (Exception e) {
            log.error("Image generation request failed, user [{}]", uid, e);
            throw new BusinessException(ResponseEnum.SYSTEM_ERROR);
        }
    }

    /**
     * Text generation request (for opening lines generation and other functions)
     *
     * @param question Generation prompt
     * @param domain Model domain

View on GitHub (pinned to 5e758547a8)