{"id":167264,"date":"2020-10-11T17:47:14","date_gmt":"2020-10-11T09:47:14","guid":{"rendered":"http:\/\/4563.org\/?p=167264"},"modified":"2020-10-11T17:47:14","modified_gmt":"2020-10-11T09:47:14","slug":"%e5%a4%a7%e5%ae%b6%e6%80%8e%e4%b9%88%e5%9c%a8-service-%e5%a4%84%e7%90%86%e9%aa%8c%e8%af%81%e5%a4%b1%e8%b4%a5%e7%9a%84%e4%bf%a1%e6%81%af%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=167264","title":{"rendered":"\u5927\u5bb6\u600e\u4e48\u5728 service \u5904\u7406\u9a8c\u8bc1\u5931\u8d25\u7684\u4fe1\u606f\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5927\u5bb6\u600e\u4e48\u5728 service \u5904\u7406\u9a8c\u8bc1\u5931\u8d25\u7684\u4fe1\u606f\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : 2351988538 <\/span>  <span><i><\/i> 7<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u6bd4\u5982\u8bf4\u6ce8\u518c\u7528\u6237\u7528\u6237\u540d\u5df2\u5b58\u5728\u4e4b\u7c7b\u7684\uff0c\u8fd9\u79cd\u4fe1\u606f\u600e\u4e48\u6bd4\u8f83\u4f18\u96c5\u7684\u5904\u7406\uff1f      <\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>7<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3700563\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : rbe <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u76ee\u524d\u662f throw new Error(), \u7136\u540e\u518d controller \u5c42 try catch<br \/>\u4e5f\u6709\u4e9b\u60c5\u51b5\u4e0b\u629b\u9519\u9700\u8981\u643a\u5e26\u4e00\u4e9b\u4e0a\u4e0b\u6587\u4e00\u5e76\u8fd4\u56de\uff0c\u5c31\u8fd4\u56de\u4e00\u4e2a\u7279\u5b9a\u7684\u6570\u636e\u7ed3\u6784\u6bd4\u5982 success \u5565\u7684\uff0c\u5728 controller \u5c42\u5224\u65ad                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3700564\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dethan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u629b\u51fa\u7279\u5b9a\u5f02\u5e38\uff0c\u7136\u540e\u7edf\u4e00\u5f02\u5e38\u5904\u7406                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3700565\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xuanbg <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u7684\u5904\u7406\u548c\u4e0a\u4e0d\u540c\uff0c\u4e0d\u629b\u51fa\u5f02\u5e38\uff0c\u76f4\u63a5\u8fd4\u56de\u4e00\u4e2a\u9519\u8bef\u4fe1\u606f\u3002<br \/>{<br \/> &#8220;success&#8221;: false,<br \/> &#8220;code&#8221;: 400,<br \/> &#8220;message&#8221;: &#8220;\u7528\u6237\u540d\u5df2\u5b58\u5728&#8221;,<br \/> &#8220;data&#8221;: null,<br \/> &#8220;option&#8221;: null<br \/>}                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3700566\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : youngxhui <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             service \u629b\u51fa\u81ea\u5b9a\u4e49\u5f02\u5e38\uff0c\u7136\u540e\u6846\u67b6\u7edf\u4e00\u5904\u7406\u5f02\u5e38                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3700567\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lyusantu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u81ea\u5b9a\u4e49\u4e00\u4e2a\u901a\u7528\u7684\u9879\u76ee\u5f02\u5e38\uff0c\u7136\u540e\u5199\u4e00\u4e2a\u5168\u5c40\u5f02\u5e38\u6355\u83b7\u5904\u7406\u5668\uff0c\u5904\u7406\u5668\u7edf\u4e00\u8fd4\u56de\u548c\u63a5\u53e3\u540c\u7ed3\u6784\u7684 JSON \u9519\u8bef\u7ed3\u679c.<\/p>\n<p>service \u4e2d\u4e3b\u52a8\u629b\u51fa\u81ea\u5b9a\u4e49\u5f02\u5e38\u5373\u53ef. \u5982: throw new ProjectException(&#8220;\u9a8c\u8bc1\u8eab\u4efd\u5931\u8d25&#8221;);<\/p>\n<p>\u629b\u51fa\u7684\u5f02\u5e38\u4f1a\u88ab\u5904\u7406\u5668\u6355\u83b7\uff0c\u7136\u540e\u8fd4\u56de {&#8220;code&#8221;:500, &#8220;message&#8221;:&#8221;\u9a8c\u8bc1\u8eab\u4efd\u5931\u8d25&#8221;, data: null}<\/p>\n<p>\u7406\u8bba\u4e0a, \u629b\u51fa\u7684\u53ef\u4ee5\u662f\u4e00\u4e2a\u679a\u4e3e,\u679a\u4e3e\u5305\u542b\u4e00\u4e2a\u9519\u8bef\u7801\u548c\u4e00\u6761\u9519\u8bef\u4fe1\u606f                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3700568\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : huijiewei <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             throw                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3700569\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : libook <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u670d\u52a1\u7aef\u7edf\u4e00\u5f00\u8f9f\u4e00\u4e2a API \u5904\u7406\u5c42\uff0c\u8bf7\u6c42\u53d1\u8fdb\u6765\u5148\u8fdb\u5165\u8fd9\u4e2a\u5c42\uff0c\u7528\u4e8e\u6821\u9a8c\u53c2\u6570\u683c\u5f0f\u3001\u8c03\u7528\u5e95\u5c42\u4e1a\u52a1\u903b\u8f91\u3001\u7ec4\u5408\u548c\u683c\u5f0f\u5316\u8fd4\u56de\u6570\u636e\u3002<br \/>\u5bf9\u4e8e\u6ce8\u518c\u65f6\u7528\u6237\u662f\u5426\u5b58\u5728\u7684\u95ee\u9898\uff0c\u662f\u5728\u6ce8\u518c\u8fc7\u7a0b\u7684\u4e8b\u52a1\u4e2d\u8fdb\u884c\uff0c\u786e\u4fdd\u7528\u6237\u4e0d\u5b58\u5728\u3001\u521b\u5efa\u7528\u6237\u4e3a\u539f\u5b50\u64cd\u4f5c\uff0c\u4e00\u65e6\u64cd\u4f5c\u5931\u8d25\uff0c\u53ef\u4ee5 throw error\uff0c\u5728 API \u5904\u7406\u5c42 catch \u8fd9\u4e2a error\uff0c\u7136\u540e\u518d\u7ec4\u5408\u597d\u9002\u5f53\u7684\u4fe1\u606f\u548c\u72b6\u6001\u7801\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002<\/p>\n<p>\u5982\u679c\u4e1a\u52a1\u8db3\u591f\u8f7b\uff0c\u4e0d\u503c\u5f97\u5355\u72ec\u5f00\u8f9f\u4e00\u4e2a API \u5904\u7406\u5c42\uff0c\u5e0c\u671b\u4ece controller \u5c42\u76f4\u63a5\u914d\u7f6e\u597d HTTP \u72b6\u6001\u7801\u548c\u8fd4\u56de\u4fe1\u606f\uff0c\u53ef\u4ee5\u4f7f\u7528 http-error \u6216 http-assert \u5305\u6765\u81ea\u52a8 throw error\uff0c\u5e76\u643a\u5e26 HTTP \u72b6\u6001\u7801\u548c\u8fd4\u56de\u6570\u636e\uff0c\u7136\u540e\u5728 API \u8def\u7531\u4e0a\u5168\u5c40\u6355\u6349 error\uff0c\u76f4\u63a5\u628a http-error \u643a\u5e26\u7684\u72b6\u6001\u7801\u548c\u8fd4\u56de\u4fe1\u606f\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002<\/p>\n<p>koa.js \u5185\u7f6e\u4e86 http-assert\/http-error \u673a\u5236\uff0chttp-assert \u7684\u6240\u6709\u65b9\u6cd5\u90fd\u53ef\u4ee5\u76f4\u63a5\u4ece ctx \uff08 Context \uff09\u4e2d\u8c03\u7528\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5927\u5bb6\u600e\u4e48\u5728 service \u5904\u7406\u9a8c&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/167264"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=167264"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/167264\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=167264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=167264"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=167264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}