mirror of
https://gitee.com/ctexthuang/hyperf-micro-svc.git
synced 2026-03-27 23:20:17 +08:00
fix : update cors and admin user cache
This commit is contained in:
44
app/Exception/Handler/MainHttpExceptionHandler.php
Normal file
44
app/Exception/Handler/MainHttpExceptionHandler.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exception\Handler;
|
||||
|
||||
use App\Constants\ResultCode;
|
||||
use App\Exception\ErrException;
|
||||
use Hyperf\HttpMessage\Exception\HttpException;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Throwable;
|
||||
|
||||
class MainHttpExceptionHandler extends BaseErrExceptionHandler
|
||||
{
|
||||
/**
|
||||
* @param Throwable $throwable
|
||||
* @param ResponseInterface $response
|
||||
* @return ResponseInterface
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function handle(Throwable $throwable, ResponseInterface $response): ResponseInterface
|
||||
{
|
||||
if ($throwable instanceof HttpException) {
|
||||
$msg = match ($throwable->getStatusCode()) {
|
||||
404 => 'The route does not exist.',
|
||||
405 => 'The HTTP method not allowed.',
|
||||
default => $throwable->getMessage(),
|
||||
};
|
||||
$throwable = new ErrException($msg,ResultCode::ERROR);
|
||||
return $this->handlerResponse($throwable,$response);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Throwable $throwable
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid(Throwable $throwable): bool
|
||||
{
|
||||
return $throwable instanceof HttpException;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user