Commit 6c8dae2f authored by 王源's avatar 王源
Browse files

修改未捕获异常返回数据格式

parent 209da1be
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -38,7 +38,12 @@ class AppExceptionHandler extends ExceptionHandler
        $this->stdoutLogger->error($msg);
        $this->logger->error($msg);
        $this->stdoutLogger->error($throwable->getTraceAsString());
        return $response->withHeader("Server", "H5Q-OA")->withStatus(500)->withBody(new SwooleStream($msg));
        // 格式化输出
        $data = json_encode([
            'code' => $throwable->getCode() ?: 400,
            'msg' => $throwable->getMessage(),
        ], JSON_UNESCAPED_UNICODE);
        return $response->withAddedHeader('content-type', 'application/json')->withBody(new SwooleStream($data));
    }

    public function isValid(Throwable $throwable): bool