src/PHPDish/Bundle/CoreBundle/EventListener/KernelExceptionListener.php
private function createForbiddenResponseForAPI()
    {
        if ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
            $response = new JsonResponse([
                'error' => '访问拒绝',
            ], Response::HTTP_FORBIDDEN);
        } else {
            $response = new JsonResponse([
                'error' => '请先登录',
                'redirect' => $this->router->generate('login'),
            ], Response::HTTP_FORBIDDEN);
        }

        return $response;
    }
private function createForbiddenResponseForAPI()
    {
        if ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
            $response = new JsonResponse([
                'error' => '访问拒绝',
            ], Response::HTTP_FORBIDDEN);
        } else {
            $response = new JsonResponse([
                'error' => '请先登录',
                'redirect' => $this->router->generate('login'),
            ], Response::HTTP_FORBIDDEN);
        }

        return $response;
    }
创建接口 403 response.

@return JsonResponse