binarywang/WxJava · error · WxErrorException

错误代码:{errorCode}, 错误信息:{errorMsg}

Error message

错误代码:{errorCode}, 错误信息:{errorMsg}

What it means

Thrown by the OkHttp minishop image-upload executor (file-based, not URL-based) when WeChat replies with a non-zero errcode. The executor uploads a file part as application/octet-stream, parses the response into WxError, and rethrows as WxErrorException when errorCode != 0. Functionally identical in shape to the generic media executor but returns a WxMinishopImageUploadResult.

Source

Thrown at weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpMinishopMediaUploadRequestExecutor.java:42

    super(requestHttp);
  }

  @Override
  public WxMinishopImageUploadResult execute(String uri, File file, WxType wxType) throws WxErrorException, IOException {

    RequestBody body = new MultipartBody.Builder()
      .setType(MediaType.parse("multipart/form-data"))
      .addFormDataPart("media",
        file.getName(),
        RequestBody.create(MediaType.parse("application/octet-stream"), file))
      .build();
    Request request = new Request.Builder().url(uri).post(body).build();

    Response response = requestHttp.getRequestHttpClient().newCall(request).execute();
    String responseContent = response.body().string();
    WxError error = WxError.fromJson(responseContent, wxType);
    if (error.getErrorCode() != 0) {
      throw new WxErrorException(error);
    }
    log.info("responseContent: {}", responseContent);

    return WxMinishopImageUploadResult.fromJson(responseContent);
  }

}

View on GitHub (pinned to 1c43293a3c)

Solutions

  1. Inspect e.getError().getErrorCode()/getErrorMsg() for the specific WeChat code.
  2. Confirm the access_token is valid before uploading.
  3. Validate image size and format against the minishop documentation before posting.
  4. Ensure you are calling the minishop-specific executor with the minishop URL constant.

Example fix

// before
WxMinishopImageUploadResult r = service.execute(url, file);
// after
try {
  WxMinishopImageUploadResult r = service.execute(url, file);
} catch (WxErrorException e) {
  log.error("minishop image upload errcode={} msg={}",
    e.getError().getErrorCode(), e.getError().getErrorMsg());
  throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

File f = ...;
if (f == null || !f.exists() || f.length() <= 0) {
  throw new IllegalArgumentException("image file required");
}
// check extension against minishop supported formats
String name = f.getName().toLowerCase();
if (!name.endsWith(".jpg") && !name.endsWith(".png")) {
  throw new IllegalArgumentException("unsupported image format");
}

Type guard

null

Try / catch

try {
  WxMinishopImageUploadResult r = service.execute(uri, file);
} catch (WxErrorException e) {
  log.error("errcode={} msg={}", e.getError().getErrorCode(), e.getError().getErrorMsg());
  throw e;
}

Prevention

When it happens

Trigger: Uploading a product/store image file via the minishop endpoint with an expired access_token, a file that exceeds the minishop size limit, an unsupported image format, or when the response body is a non-JSON error page.

Common situations: access_token expired between requests; image too large or wrong format (e.g. webp where jpg/png expected); filename with no extension; gateway returning HTML on overload.

Related errors


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