<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之旅 廣告
                ``` <?php namespace app\lib\exception; use Exception; use Throwable; class BaseException extends Exception { public $code = 400; public $msg = '發生錯誤'; public $statusCode = 500; public function __construct($params = []) { if (!is_array($params)) return; if (array_key_exists('code', $params)) $this->code = $params['code']; if (array_key_exists('msg', $params)) $this->msg = $params['msg']; if (array_key_exists('statusCode', $params)) $this->statusCode = $params['statusCode']; } } ``` 創建自定義異常類?app/lib/exception/ExceptionHandler.php ``` <?php namespace app\lib\exception; use Throwable; use think\exception\Handle; use think\Response; class ExceptionHandler extends Handle { public $code; public $msg; public $statusCode;//http狀態碼 public function render($request, Throwable $e): Response { if ($e instanceof BaseException) { $this->code = $e->code; $this->msg = $e->msg; $this->statusCode = $e->statusCode; } else { // debug開啟 顯示默認的異常 if (env('APP_DEBUG')) return parent::render($request, $e); $this->code = 500; $this->msg = '服務器異常'; $this->statusCode = 500; } $res = [ 'msg' => $this->msg, 'code' => $this->code, ]; return json($res, $this->statusCode); } } ``` 修改thinkphp6異常類使用自定義的異常類?app/provider.php ``` <?php use app\lib\exception\ExceptionHandler; use app\Request; use app\ExceptionHandle; // 容器Provider定義文件 return [ 'think\Request' => Request::class, 'think\exception\Handle' => ExceptionHandler::class, // 'think\exception\Handle' => ExceptionHandle::class, ]; ``` 在控制器中使用拋出自定義異常類?app/index/controller/Index.php ``` <?php namespace app\index\controller; use app\BaseController; use think\facade\Request; use app\lib\exception\BaseException; class Index extends BaseController { public function index() { throw (new BaseException(['code'=>400,'statusCode'=>404,'msg'=>'異常'])); return '111'; } } ```
                  <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>

                              哎呀哎呀视频在线观看