binarywang/WxJava · error · WxErrorException

响应为空

Error message

响应为空

What it means

Thrown by `ensureSuccess` in the AI Speech dialog service when the parsed `AispeechApiResponse` is null, i.e. the HTTP body could not be deserialized into a response object at all. It is a WxErrorException. A separate branch handles non-zero `code` with the server's msg; this specific message is only the null-response case.

Source

Thrown at weixin-java-aispeech/src/main/java/me/chanjar/weixin/aispeech/api/impl/WxAispeechDialogServiceImpl.java:120

    Type type = new TypeToken<AispeechApiResponse<DialogResult>>() { } .getType();
    AispeechApiResponse<DialogResult> result = WxGsonBuilder.create().fromJson(responseJson, type);
    ensureSuccess(result);

    DialogResult dialogResult = result.getData();
    if (dialogResult != null && looksLikeJson(dialogResult.getAnswer())) {
      dialogResult.setRawAnswer(WxGsonBuilder.create().fromJson(dialogResult.getAnswer(), JsonElement.class));
    }
    return dialogResult;
  }

  private boolean looksLikeJson(String value) {
    return StringUtils.isNotBlank(value) && (value.startsWith("{") || value.startsWith("["));
  }

  private void ensureSuccess(AispeechApiResponse<?> response) throws WxErrorException {
    if (response == null) {
      throw new WxErrorException("响应为空");
    }
    if (response.getCode() == null || response.getCode() != 0) {
      throw new WxErrorException(WxError.builder()
        .errorCode(response.getCode() == null ? -1 : response.getCode())
        .errorMsg(response.getMsg())
        .build());
    }
  }
}

View on GitHub (pinned to 1c43293a3c)

Solutions

  1. Enable request/response logging to capture the raw body returned by the dialog endpoint.
  2. Verify `dialogApiBaseUrl` is correct and reachable; check for proxy/gateway HTML responses.
  3. Confirm the AI Speech service account/network allows egress to the endpoint.
  4. If the contract changed, update the SDK or align the server response to the expected JSON.
Defensive patterns

Strategy: try-catch

Validate before calling

// Not applicable: cannot pre-validate a remote null response. Validate connectivity instead.
if (StringUtils.isBlank(configStorage.getDialogApiBaseUrl())) {
    throw new IllegalStateException("dialogApiBaseUrl is not configured");
}

Try / catch

try {
    WxAispeechDialogResult r = service.dialog(...);
} catch (WxErrorException e) {
    if ("响应为空".equals(e.getMessage())) {
        // log raw transport details; likely wrong endpoint or non-JSON body
        log.error("Dialog returned empty/unparseable body from {}", configStorage.getDialogApiBaseUrl(), e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Dialog API returns an empty or non-JSON body, a network/proxy returns an HTML error page, the endpoint URL is wrong (404 body), or the response model fails to deserialize so the caller receives null.

Common situations: Wrong `dialogApiBaseUrl`; gateway/proxy intercepting with an HTML error; region or environment mismatch; API contract change after an SDK/server version bump.

Related errors


AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14). Data as JSON: /api/errors/3e0de4bf289a63a8. Report an issue: GitHub.