binarywang/WxJava · warning · RuntimeException

the responseContent cannot be empty

Error message

the responseContent cannot be empty

What it means

Thrown as RuntimeException when the response content passed to the private parse() method in WxMaImmediateDeliveryServiceImpl is blank (null, empty, or whitespace only). This is a defensive guard before JSON parsing in the immediate delivery (即时配送) service. Since parse() is a private internal method, this error indicates the WeChat API returned an empty body where content was expected.

Source

Thrown at weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaImmediateDeliveryServiceImpl.java:228

    WxMaBaseResponse response = WxMaGsonBuilder.create().fromJson(responseContent, WxMaBaseResponse.class);
    if (response.getErrcode() == -1) {
      throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
    }
    return response;
  }

  /**
   * 解析响应.
   *
   * @param responseContent 响应内容
   * @param valueType       类型
   * @param <T>             类型
   * @return 结果
   * @throws WxErrorException 异常
   */
  private <T extends WxMaDeliveryBaseResponse> T parse(final String responseContent, final Class<T> valueType) throws WxErrorException {
    if (StringUtils.isBlank(responseContent)) {
      throw new RuntimeException("the responseContent cannot be empty");
    }
    // 解析成Json对象
    JsonObject jsonObject = GsonParser.parse(responseContent);
    // 是否为微信错误响应 当 errcode==0 或者 不存在 还需要看 运力方 resultcode 状态码
    JsonElement element = jsonObject.get(ERR_CODE);
    // 正常响应下不会有该字段返回
    if (!ObjectUtils.isEmpty(element) && SUCCESS_CODE != element.getAsInt()) {
      throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
    }
    // 是否为运力方错误响应
    JsonElement delivery = jsonObject.get(SF_ERR_CODE);
    if (!ObjectUtils.isEmpty(delivery) && SUCCESS_CODE != delivery.getAsInt()) {
      throw new WxErrorException(jsonObject.get(SF_ERR_MSG).getAsString());
    }
    // 解析成对应响应对象
    return WxMaDeliveryBaseResponse.fromJson(responseContent, valueType);
  }

View on GitHub (pinned to 1c43293a3c)

Solutions

  1. This is an internal library guard — check network stability that may cause empty HTTP responses
  2. Verify the delivery API endpoint URL is correct and accessible from your server
  3. Check if WeChat is experiencing intermittent issues by retrying the same request
  4. Report as a library issue if WeChat legitimately returns empty bodies, so the library can handle it gracefully
Defensive patterns

Strategy: try-catch

Validate before calling

// Cannot validate directly — parse() is private and called internally.
// Ensure network stability and retry at the delivery service call level.

Try / catch

try {
  deliveryService.addOrder(request);
} catch (RuntimeException e) {
  if (e.getMessage().contains("responseContent cannot be empty")) {
    log.warn("WeChat returned empty response for delivery API — retrying");
    // retry once or queue for later processing
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: A delivery API method (e.g., addOrder, getOrder, cancelOrder) receives an empty or whitespace-only response body from WeChat and internally passes it to parse().

Common situations: Network issue causing truncated or empty response body; WeChat API returning empty body on certain server-side error conditions; HTTP client stripping the response body due to encoding issues; connection reset after headers but before body.

Related errors


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