<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # API接口中的異常處理 >[success]在API接口的開發過程中,使用TP自帶的異常處理機制,可能并不能滿足實際需求。 >TP默認是直接拋出異常,而API接口通常返回的是json數據格式。所以需要對異常類進行重寫。 ## 重寫異常處理的`render`方法 ### 重寫異常處理類 ~~~php <?php namespace app\common\lib\exception; use think\exception\Handle; class ApiExceptionHandle extends Handle { private $httpCode = 400; public function render(\Exception $e) { if(config("app_debug")==true){ return parent::render($e); } if($e instanceof ApiException){ $this->httpCode = $e->httpCode; } $data = [ "code"=>0, "msg"=>$e->getMessage(), 'data'=>[] ]; return json($data,$this->httpCode); } } ~~~ ### 重寫內部錯誤異常處理 ~~~ <?php namespace app\common\lib\exception; use think\Exception; class ApiException extends Exception { public $message=""; public $httpCode=500; public $code=0; public function __construct($message = '',$httpCode=0,$code=0) { $this->message = $message; $this->httpCode = $httpCode; $this->code =$code; } } ~~~ >[danger]重寫異常類之后,需要在配置文件中,配置成自定義的異常類 ~~~ // 異常處理handle類 留空使用 \think\exception\Handle 'exception_handle' => 'app\common\lib\exception\ApiExceptionHandle', ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看