48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* MineAdmin is committed to providing solutions for quickly building web applications
|
|
* Please view the LICENSE file that was distributed with this source code,
|
|
* For the full copyright and license information.
|
|
* Thank you very much for using MineAdmin.
|
|
*
|
|
* @Author X.Mo<root@imoi.cn>
|
|
* @Link https://gitee.com/xmo/MineAdmin
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Builder\Exception\Handler;
|
|
|
|
use Hyperf\ExceptionHandler\ExceptionHandler;
|
|
use Hyperf\HttpMessage\Stream\SwooleStream;
|
|
use Hyperf\Utils\Codec\Json;
|
|
use Builder\Exception\NoPermissionException;
|
|
use Builder\Helper\BaseCode;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Throwable;
|
|
|
|
/**
|
|
* Class TokenExceptionHandler
|
|
* @package Builder\Exception\Handler
|
|
*/
|
|
class NoPermissionExceptionHandler extends ExceptionHandler
|
|
{
|
|
public function handle(Throwable $throwable, ResponseInterface $response): ResponseInterface
|
|
{
|
|
$this->stopPropagation();
|
|
$format = [
|
|
'success' => false,
|
|
'message' => $throwable->getMessage(),
|
|
'code' => BaseCode::NO_PERMISSION,
|
|
];
|
|
return $response->withHeader('Server', 'MineAdmin')
|
|
->withAddedHeader('content-type', 'application/json; charset=utf-8')
|
|
->withStatus(403)->withBody(new SwooleStream(Json::encode($format)));
|
|
}
|
|
|
|
public function isValid(Throwable $throwable): bool
|
|
{
|
|
return $throwable instanceof NoPermissionException;
|
|
}
|
|
}
|