异常啊异常

This commit is contained in:
Aether
2025-09-26 17:27:15 +08:00
parent d7880f99c9
commit afd384a52a
2 changed files with 6 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Aether;
use Aether\Exception\BusinessException;
use Aether\Exception\ValidationFailedException;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Database\Model\ModelNotFoundException;
use Hyperf\ExceptionHandler\ExceptionHandler;
@@ -26,6 +27,9 @@ class GlobalExceptionHandler extends ExceptionHandler
public function handle(Throwable $throwable, ResponseInterface $response): MessageInterface|ResponseInterface
{
if ($throwable instanceof ValidationFailedException) {
return $response->withBody(new SwooleStream($throwable->getMessage()));
}
// 处理业务异常
if ($throwable instanceof BusinessException) {
$data = [