{"record":{"id":"07f29765116d7aa5","repo":"binarywang/WxJava","slug":"errorcode-errormsg-07f297","errorCode":null,"errorMessage":"错误代码：{errorCode}, 错误信息：{errorMsg}","messagePattern":"错误代码：(.+?), 错误信息：(.+?)","errorType":"exception","errorClass":"WxErrorException","httpStatus":null,"severity":"error","filePath":"weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpMediaUploadRequestExecutor.java","lineNumber":40,"sourceCode":"    super(requestHttp);\n  }\n\n  @Override\n  public WxMediaUploadResult execute(String uri, File file, WxType wxType) throws WxErrorException, IOException {\n\n    RequestBody body = new MultipartBody.Builder()\n      .setType(MediaType.parse(\"multipart/form-data\"))\n      .addFormDataPart(\"media\",\n        file.getName(),\n        RequestBody.create(MediaType.parse(\"application/octet-stream\"), file))\n      .build();\n    Request request = new Request.Builder().url(uri).post(body).build();\n\n    Response response = requestHttp.getRequestHttpClient().newCall(request).execute();\n    String responseContent = response.body().string();\n    WxError error = WxError.fromJson(responseContent, wxType);\n    if (error.getErrorCode() != 0) {\n      throw new WxErrorException(error);\n    }\n    return WxMediaUploadResult.fromJson(responseContent);\n  }\n\n}\n","sourceCodeStart":22,"sourceCodeEnd":46,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpMediaUploadRequestExecutor.java#L22-L46","documentation":"Thrown by the OkHttp media-upload request executor after the WeChat server replies with a non-zero errcode. The executor builds a multipart/form-data body (a 'media' part typed application/octet-stream), runs the OkHttp call, parses response.body().string() into a WxError, and on error.getErrorCode() != 0 rethrows it as WxErrorException. It represents a WeChat API-level rejection of a media/material upload, not an HTTP transport failure.","triggerScenarios":"Calling any media-upload endpoint that uses OkHttpMediaUploadRequestExecutor (temporary/permanent material upload) when the access_token is invalid/expired, the file exceeds WeChat size limits, the media format/extension is unsupported, or the response body is not valid JSON (e.g. an HTML gateway error page that yields a parsed errorCode other than 0).","commonSituations":"Expired access_token used after long idle; image larger than the documented limit; missing/incorrect file extension; corporate proxy returning HTML on overload; wrong wxType passed so the error code translation misfires.","solutions":["Catch WxErrorException and read e.getError().getErrorCode()/getErrorMsg() to get the exact WeChat code, then look it up in WeChat's global return-code table.","Verify the access_token is fresh and the config storage auto-refresh is enabled before the upload.","Check the file against WeChat limits (size, format, extension) before posting.","Confirm the request executor type and URL constant match the WeChat endpoint you intend to call."],"exampleFix":"// before\nWxMediaUploadResult r = service.executeMediaUploadRequest(url, file);\n// after\ntry {\n  WxMediaUploadResult r = service.executeMediaUploadRequest(url, file);\n} catch (WxErrorException e) {\n  log.error(\"upload failed errcode={} msg={}\",\n    e.getError().getErrorCode(), e.getError().getErrorMsg());\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"// validate before upload\nFile f = ...;\nlong MAX = 2L * 1024 * 1024; // example limit\nif (!f.exists() || f.length() > MAX) {\n  throw new IllegalArgumentException(\"invalid media file\");\n}\nif (!service.getWxCpConfigStorage().isAccessTokenExpired()) {\n  // token looks fresh\n}","typeGuard":"null","tryCatchPattern":"try {\n  WxMediaUploadResult r = executor.execute(uri, file, wxType);\n} catch (WxErrorException e) {\n  WxError err = e.getError();\n  log.error(\"media upload errcode={} msg={}\", err.getErrorCode(), err.getErrorMsg());\n  // token errors -> refresh & retry once; others -> propagate\n  throw e;\n}","preventionTips":["Pre-check file size/format against the WeChat media limits.","Keep access_token auto-refresh enabled and verify it before bulk uploads.","Log errcode/msg on every WxErrorException to classify root causes."],"tags":["weixin-api","okhttp","media-upload","network"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}