Browse Source

调整异常

master
xyiege 1 year ago
parent
commit
efdbe17e50
  1. 1
      app/ExceptionHandle.php
  2. 3
      app/api/config.php
  3. 2
      app/api/middleware.php
  4. 2
      app/api/service/UserService.php
  5. 1
      app/common.php
  6. 3
      composer.json
  7. 1
      config/app.php
  8. 2
      cores/exception/BaseException.php

1
app/ExceptionHandle.php

@ -9,6 +9,7 @@ use think\exception\HttpResponseException;
use think\exception\ValidateException; use think\exception\ValidateException;
use think\Response; use think\Response;
use Throwable; use Throwable;
use cores\exception\BaseException;
/** /**
* 应用异常处理类 * 应用异常处理类

3
app/api/config.php

@ -0,0 +1,3 @@
<?php
// 配置输出json
return [];

2
app/api/middleware.php

@ -9,6 +9,6 @@ return [
// \app\admin\middleware\SystemLog::class, // \app\admin\middleware\SystemLog::class,
// Csrf安全校验 // Csrf安全校验
\app\api\middleware\CsrfMiddleware::class, // \app\api\middleware\CsrfMiddleware::class,
]; ];

2
app/api/service/UserService.php

@ -21,7 +21,7 @@ class UserService {
// 异常处理 // 异常处理
if(!isset($drs)){ if(!isset($drs)){
throwError('用户不存在'); throwError('用户不存在');
return false; return -1;
}else{ }else{
// 对比密码 // 对比密码
if($drs['password'] != $pass){ if($drs['password'] != $pass){

1
app/common.php

@ -5,6 +5,7 @@ use app\common\service\AuthService;
use cores\exception\BaseException; use cores\exception\BaseException;
use think\facade\Cache; use think\facade\Cache;
if (!function_exists('__url')) { if (!function_exists('__url')) {
/** /**

3
composer.json

@ -37,7 +37,8 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"app\\": "app" "app\\": "app",
"cores\\": "cores"
}, },
"psr-0": { "psr-0": {
"": "extend/" "": "extend/"

1
config/app.php

@ -23,6 +23,7 @@ return [
// 应用映射(自动多应用模式有效) // 应用映射(自动多应用模式有效)
'app_map' => [ 'app_map' => [
Env::get('easyadmin.admin', 'douyin') => 'admin', Env::get('easyadmin.admin', 'douyin') => 'admin',
'api' => 'api',
], ],
// 后台别名 // 后台别名
'admin_alias_name' => Env::get('easyadmin.admin', 'douyin'), 'admin_alias_name' => Env::get('easyadmin.admin', 'douyin'),

2
cores/exception/BaseException.php

@ -29,7 +29,7 @@ class BaseException extends Exception
public function __construct($params = []) public function __construct($params = [])
{ {
parent::__construct(); parent::__construct();
$this->status = $params['status'] ?? config('status.error'); $this->status = $params['status'] ?? 1000;
$this->message = $params['message'] ?? '很抱歉,服务器内部错误'; $this->message = $params['message'] ?? '很抱歉,服务器内部错误';
$this->data = $params['data'] ?? []; $this->data = $params['data'] ?? [];
} }

Loading…
Cancel
Save