异常处理器兼容ModelNotFoundException返回404

This commit is contained in:
堂吉诃德拉曼查的英豪
2026-08-06 15:34:13 +08:00
parent 454139ac83
commit 64aec80889

View File

@@ -18,6 +18,7 @@ use Hyperf\HttpMessage\Stream\SwooleStream;
use Hyperf\RpcClient\Exception\RequestException;
use Dhd\Micro\Core\Exception\BusinessException;
use Dhd\Micro\Core\Exception\ValidateException;
use Hyperf\Database\Model\ModelNotFoundException;
use Dhd\Micro\Core\Trait\RpcContextTrait;
@@ -36,9 +37,13 @@ class JsonRpcBusinessExceptionHandler extends ExceptionHandler
$id = $request ? $request->getAttribute('request_id', null) : null; // Hyperf 注入的 ID
$isError = !($throwable instanceof BusinessException)
&& !($throwable instanceof ValidateException)
&& !($throwable instanceof RequestException);
&& !($throwable instanceof RequestException)
&& !($throwable instanceof ModelNotFoundException);
if ($isError) {
if ($throwable instanceof ModelNotFoundException) {
$code = 404;
$message = $throwable->getMessage();
} elseif ($isError) {
$code = 500;
$message = '服务器内部错误';
} else {