1-2\u3001\u6355\u83b7\u5f02\u5e38\u5e76\u5904\u7406<\/strong><\/span><\/div>\n\u6355\u83b7feign\u5f02\u5e38\u6709\u4e24\u79cd\u65b9\u6cd5\uff0c\u4e00\u79cd\u662f\u5728\u8c03\u7528\u5904 try...catch...\uff1b\u4e00\u79cd\u662f\u7edf\u4e00\u6355\u83b7\u5904\u7406\uff0c\u63a8\u8350\u540e\u8005\uff1b<\/p>\n
\u7edf\u4e00\u6355\u83b7\uff1a\u589e\u52a0\u4e00\u4e2a\u914d\u7f6e\u7c7b\uff0c\u5b9e\u73b0ErrorDecoder\u63a5\u53e3\uff0c\u5728\u91cc\u9762\u5c31\u53ef\u4ee5\u6355\u83b7feign\u5f02\u5e38\u5e76\u4e0a\u629b\u81ea\u5b9a\u4e49\u5f02\u5e38\u4e86\uff1b<\/p>\n
\u7136\u540e\uff0c\u5728\u6211\u4eec\u4e4b\u524d\u5199\u7684\u7edf\u4e00\u5f02\u5e38\u5904\u7406\u7684\u5c31\u53ef\u4ee5\u6355\u83b7\u548c\u5904\u7406\u8fd9\u4e2a\u5f02\u5e38\uff0c\u5e76\u8fd4\u56de\u53cb\u597d\u7684\u4fe1\u606f\u7ed9\u7528\u6237\u4e86\uff1b<\/p>\n
\r\n@Configuration\r\npublic class FeignErrorDecoder implements ErrorDecoder\r\n{\r\n public static final Logger log = LoggerFactory.getLogger(FeignErrorDecoder.class);\r\n @Override\r\n public Exception decode(String methodKey, Response response)\r\n {\r\n try\r\n {\r\n \/\/ \u83b7\u53d6\u5f02\u5e38\u4fe1\u606f\r\n String message = Util.toString(response.body().asReader());\r\n JSONObject jsonObject = JSONObject.parseObject(message);\r\n log.error(message); \/\/\u8bb0\u5f55\u65e5\u5fd7\r\n \/\/\u76f4\u63a5\u4e0a\u629b\u81ea\u5b9a\u4e49\u5f02\u5e38\r\n \/\/ return new BizException(jsonObject.getInteger(\"code\"), jsonObject.getString(\"msg\"));\r\n return new BizException(jsonObject.getInteger(\"resultCode\"), jsonObject.getString(\"resultMsg\"));\r\n }\r\n catch (Exception ex)\r\n {\r\n \/\/1\u3001\u8c03\u7528\u53c2\u6570\u5f02\u5e38\r\n if (response.status() >= 400 && response.status() <= 500)\r\n {\r\n return new BizException(ResultCode.INVALID_REQUEST);\r\n }\r\n else\r\n {\r\n return new BizException(ResultCode.INTERNAL_SERVER_ERROR);\r\n }\r\n }\r\n }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"\u589e\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff0cfeign\u5f00\u542f\u7194\u65ad\u540e\uff0c\u8fdc\u7aef\u670d\u52a1\u7684\u5f02\u5e38\u4f1a\u88ab\u6d88\u5316\uff0c\u800c\u8d70\u7194\u65ad\u65b9\u6cd5\uff1b\u6240\u4ee5\uff0c\u9700\u8981\u4ee5\u4e0b\u914d\u7f6e\u914d\u7f6e\u6765\u5173\u95ed\u7194\u65ad\uff0c\u597d […]<\/p>\n","protected":false},"author":1903,"featured_media":212762,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-212748","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/212748","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1903"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=212748"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/212748\/revisions"}],"predecessor-version":[{"id":212772,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/212748\/revisions\/212772"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/212762"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=212748"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=212748"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=212748"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}