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
- Enable request/response logging to capture the raw body returned by the dialog endpoint.
- Verify `dialogApiBaseUrl` is correct and reachable; check for proxy/gateway HTML responses.
- Confirm the AI Speech service account/network allows egress to the endpoint.
- 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
- Point dialogApiBaseUrl at the correct environment endpoint.
- Ensure no proxy/gateway returns HTML for the API path.
- Log raw response bodies during integration to catch contract drift.
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
- X-OPENAI-TOKEN不能为空,请先调用getAccessToken或手动设置
- X-APPID不能为空
- 知识助理请求需要配置appid
- 知识助理请求需要配置secretKey
- HmacSHA256 signature failed
AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14).
Data as JSON: /api/errors/3e0de4bf289a63a8.
Report an issue: GitHub.