From 210f8449fc876e1744a91011bbb09cc7c0a0e177 Mon Sep 17 00:00:00 2001 From: "453530270@qq.com" Date: Sun, 6 Oct 2024 20:43:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=80=9A=E7=94=A8=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/common.php b/app/common.php index 7c3c724..757f4b3 100644 --- a/app/common.php +++ b/app/common.php @@ -2,6 +2,7 @@ // 应用公共文件 use app\common\service\AuthService; +use cores\exception\BaseException; use think\facade\Cache; if (!function_exists('__url')) { @@ -121,4 +122,17 @@ if (!function_exists('auth')) { return $check; } +} + +/** + * 输出错误信息 + * @param string $message 报错信息 + * @param int|null $status 状态码,默认为配置文件status.error + * @param array $data 附加数据 + * @throws BaseException + */ +function throwError(string $message, ?int $status = null, array $data = []) +{ + is_null($status) && $status = config('status.error'); + throw new BaseException(['status' => $status, 'message' => $message, 'data' => $data]); } \ No newline at end of file