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
- Inspect e.getError().getErrorCode()/getErrorMsg() for the specific WeChat code.
- Confirm the access_token is valid before uploading.
- Validate image size and format against the minishop documentation before posting.
- 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
- Validate image size/format before posting.
- Keep access_token fresh.
- Use the minishop-specific executor and URL constant.
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
- 错误代码:{errorCode}, 错误信息:{errorMsg}
- 错误代码:{errorCode}, 错误信息:{errorMsg}
- 上传失败,服务器响应空 url:%s param:%s
- 微信服务端异常,超出重试次数
- 获取 suite token 失败
AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14).
Data as JSON: /api/errors/a0b39ea126c7edaf.
Report an issue: GitHub.