binarywang/WxJava · error · WxErrorException
错误代码:{errorCode}, 错误信息:{errorMsg}
Error message
错误代码:{errorCode}, 错误信息:{errorMsg} What it means
Thrown by the OkHttp minishop (small-store) customized image-upload executor when WeChat returns a non-zero errcode. Unlike the plain media executor, the body carries form fields resp_type, upload_type and img_url (image-by-URL upload) instead of a file part. The response body is parsed into WxError and rethrown as WxErrorException when errorCode != 0.
Source
Thrown at weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpMinishopMediaUploadRequestCustomizeExecutor.java:51
.addFormDataPart("upload_type", this.uploadType)
.addFormDataPart("media", file.getName(), RequestBody.create(MediaType.parse("application/octet-stream"), file))
.build();
}
else {
body = new MultipartBody.Builder()
.setType(MediaType.parse("multipart/form-data"))
.addFormDataPart("resp_type", this.respType)
.addFormDataPart("upload_type", this.uploadType)
.addFormDataPart("img_url", this.imgUrl)
.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 WxMinishopImageUploadCustomizeResult.fromJson(responseContent);
}
}
View on GitHub (pinned to 1c43293a3c)
Solutions
- Read e.getError().getErrorCode()/getErrorMsg() for the precise WeChat code and act on it.
- Ensure img_url is publicly reachable over HTTPS and returns a supported image content-type.
- Verify resp_type/upload_type are among the values documented for the minishop image API.
- Make sure the access_token is valid and refreshed.
Example fix
// before
WxMinishopImageUploadCustomizeResult r = service.execute(url, info);
// after
try {
WxMinishopImageUploadCustomizeResult r = service.execute(url, info);
} catch (WxErrorException e) {
log.error("minishop customize upload errcode={} msg={}",
e.getError().getErrorCode(), e.getError().getErrorMsg());
throw e;
} Defensive patterns
Strategy: validation
Validate before calling
String imgUrl = info.getImgUrl();
if (imgUrl == null || !imgUrl.startsWith("https://")) {
throw new IllegalArgumentException("img_url must be a public HTTPS url");
}
Set<String> ok = Set.of("image/png", "image/jpeg");
if (!ok.contains(info.getRespType())) {
throw new IllegalArgumentException("unsupported resp_type");
} Type guard
null
Try / catch
try {
WxMinishopImageUploadCustomizeResult r = service.execute(uri, info);
} catch (WxErrorException e) {
log.error("errcode={} msg={}", e.getError().getErrorCode(), e.getError().getErrorMsg());
throw e;
} Prevention
- Ensure img_url is HTTPS and publicly fetchable by WeChat.
- Validate resp_type/upload_type against the minishop docs.
- Refresh access_token before the call.
When it happens
Trigger: Calling the minishop customized image upload with an invalid/expired access_token, an img_url that is unreachable or not HTTPS, an unsupported resp_type/upload_type value, or when WeChat cannot fetch the supplied image URL.
Common situations: img_url pointing to a non-public or HTTP-only CDN; access_token expired; wrong resp_type (e.g. not matching the expected response container); upstream WeChat gateway returning a non-JSON error body that deserializes to a non-zero code.
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/604848acc88da368.
Report an issue: GitHub.