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