<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 異常處理 路由如果沒有匹配到任何頁面,會調用配置 error_controller_name 指定的異常處理類,默認為GoController::class。 ~~~ public function onExceptionHandle(\Throwable $e) { if ($this->whoopsConfig->isEnable() && Server::$instance->getServerConfig()->isDebug()) { throw $e; } if ($this->clientData->getResponse() != null) { $this->response->withStatus(404); $this->response->withHeader("Content-Type", "text/html;charset=UTF-8"); if($e instanceof RouteException) { $msg = '404 Not found / ' . $e->getMessage(); return $msg; }else if ($e instanceof AccessDeniedException) { $this->response->withStatus(401); $msg = '401 Access denied / ' . $e->getMessage(); return $msg; }else if($e instanceof ResponseException){ $this->response->withStatus(200); return $this->errorResponse($e->getMessage(), $e->getCode()); }else if ($e instanceof AlertResponseException){ $this->response->withStatus(500); return $this->errorResponse($e->getMessage(), $e->getCode()); } } return parent::onExceptionHandle($e); } ~~~ # 自定義異常處理 自定義異常處理,有2個時機。 >[info] 如果異常發生時,代碼沒有執行到控制器里比如404,405,則會調用GoController::onExceptionHandle 的方法進行處理。也就是 error_controller_name 配置的異常處理類。該類需要繼承 GoController 。 >[warning] 如果異常發生時,已經執行到控制器里,比如自己throw了一個異常,會優先調用該控制器里的onExceptionHandle 方法。 如果需要自定義錯誤處理,請注意異常發生的時機。 # 自定義處理異常案例 ~~~ <?php /** * Created by PhpStorm. * User: anythink * Date: 2019/5/31 * Time: 6:26 PM */ namespace app\Controller; use ESD\Go\GoController; class ExceptionClass extends GoController{ function onExceptionHandle(\Throwable $e) { $this->response->withHeader("content-type",'text/html;charset=utf-8'); if($e instanceof \Exception){ return '攔截所有異常'; } return parent::onExceptionHandle($e); // TODO: Change the autogenerated stub } } ~~~ 配置文件 ~~~ route: error_controller_name: app\Controller\ExceptionClass ~~~ # 框架提供的可用異常 該異常框架內部不會拋出,均由用戶自行使用。 ## ResponseException 該異常會被捕獲并返回message,code,如果不是ajax請求會返回。 ~~~ 錯誤消息 aaa ~~~ 如果是ajax請求會返回。 ~~~ { "code": 23333, "msg": "aaa", "data": null } ~~~ ## AlertResponseException 該異常會捕獲并返回 http500 , 內部服務器錯誤,日志會記錄詳細的錯誤信息,用于系統出現問題的時候調用。 ~~~ 錯誤消息 內部服務器錯誤,請稍后再試 ~~~ 如果是ajax請求會返回 ~~~ { "code": 500, "msg": "內部服務器錯誤,請稍后再試", "data": null } ~~~
                  <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>

                              哎呀哎呀视频在线观看