异常啊异常
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Aether;
|
namespace Aether;
|
||||||
|
|
||||||
use Aether\Exception\BusinessException;
|
use Aether\Exception\BusinessException;
|
||||||
|
use Aether\Exception\ValidationFailedException;
|
||||||
use Hyperf\Contract\StdoutLoggerInterface;
|
use Hyperf\Contract\StdoutLoggerInterface;
|
||||||
use Hyperf\Database\Model\ModelNotFoundException;
|
use Hyperf\Database\Model\ModelNotFoundException;
|
||||||
use Hyperf\ExceptionHandler\ExceptionHandler;
|
use Hyperf\ExceptionHandler\ExceptionHandler;
|
||||||
@@ -26,6 +27,9 @@ class GlobalExceptionHandler extends ExceptionHandler
|
|||||||
|
|
||||||
public function handle(Throwable $throwable, ResponseInterface $response): MessageInterface|ResponseInterface
|
public function handle(Throwable $throwable, ResponseInterface $response): MessageInterface|ResponseInterface
|
||||||
{
|
{
|
||||||
|
if ($throwable instanceof ValidationFailedException) {
|
||||||
|
return $response->withBody(new SwooleStream($throwable->getMessage()));
|
||||||
|
}
|
||||||
// 处理业务异常
|
// 处理业务异常
|
||||||
if ($throwable instanceof BusinessException) {
|
if ($throwable instanceof BusinessException) {
|
||||||
$data = [
|
$data = [
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ namespace Aether;
|
|||||||
use Hyperf\Context\Context;
|
use Hyperf\Context\Context;
|
||||||
use Hyperf\ExceptionHandler\ExceptionHandler;
|
use Hyperf\ExceptionHandler\ExceptionHandler;
|
||||||
use Hyperf\HttpMessage\Stream\SwooleStream;
|
use Hyperf\HttpMessage\Stream\SwooleStream;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
@@ -16,10 +14,9 @@ use function Hyperf\Support\env;
|
|||||||
|
|
||||||
class RpcExceptionHandler extends ExceptionHandler
|
class RpcExceptionHandler extends ExceptionHandler
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public function handle(Throwable $throwable, ResponseInterface $response): ResponseInterface
|
public function handle(Throwable $throwable, ResponseInterface $response): ResponseInterface
|
||||||
{var_dump($throwable->getMessage());
|
{
|
||||||
|
var_dump($throwable->getMessage());
|
||||||
try {
|
try {
|
||||||
// 获取请求ID(用于日志追踪)
|
// 获取请求ID(用于日志追踪)
|
||||||
$requestId = Context::get('request_id', '');
|
$requestId = Context::get('request_id', '');
|
||||||
|
|||||||
Reference in New Issue
Block a user