Browse Source

优化请求头部全部开发,错误返回请求错误码2

master
wanghongjun 1 month ago
parent
commit
517211f0a5
  1. 14
      app/controller/admin/Base.php
  2. 14
      app/controller/api/Base.php

14
app/controller/admin/Base.php

@ -85,12 +85,16 @@ class Base extends BaseController {
$return['debug'] = $this->debug;
}
// 根据 code 映射 HTTP 状态码
$httpCode = match($code) {
ReturnCode::AUTH_ERROR => 401,
ReturnCode::ACCESS_TOKEN_TIMEOUT => 401,
ReturnCode::INVALID => 404,
switch($code) {
case ReturnCode::AUTH_ERROR:
case ReturnCode::ACCESS_TOKEN_TIMEOUT:
$httpCode = 401;
break;
case ReturnCode::INVALID:
$httpCode = 404;
//ReturnCode::NO_PERMISSION => 403,
default => 400,
default :
$httpCode = 400;
};
return json($return, $httpCode);
}

14
app/controller/api/Base.php

@ -41,12 +41,16 @@ class Base extends BaseController {
$return['debug'] = $this->debug;
}
// 根据 code 映射 HTTP 状态码
$httpCode = match($code) {
ReturnCode::AUTH_ERROR => 401,
ReturnCode::ACCESS_TOKEN_TIMEOUT => 401,
ReturnCode::INVALID => 404,
switch($code) {
case ReturnCode::AUTH_ERROR:
case ReturnCode::ACCESS_TOKEN_TIMEOUT:
$httpCode = 401;
break;
case ReturnCode::INVALID:
$httpCode = 404;
//ReturnCode::NO_PERMISSION => 403,
default => 400,
default :
$httpCode = 400;
};
return json($return, $httpCode);
}

Loading…
Cancel
Save