responseDenied

Crea y devuelve una respuesta de denegación de la API.
Si no se proporcionan parámetros, el estado HTTP y el mensaje de error tendrán valores por defecto.

@param string $message
@param int $httpStatusCode
@return Response
508988
public function responseDenied ($message = "", $httpStatusCode = Response::HTTP_NOT_FOUND)
    {
        $response['state'] = $this::STATE_ERROR;
        $response['msg'] = $this->translator->trans($message);

        $view = View::create()
            ->setStatusCode($httpStatusCode)
            ->setData($response);

        return $this->viewhandler->handle($view);
    }
656241
public function respondForbidden($message = null): JsonResponse
    {
        return $this->setStatusCode(IlluminateResponse::HTTP_FORBIDDEN)
            ->respondWithError(ApiResponse::CODE_FORBIDDEN, $message);
    }
689806
public static HttpResponse newResponse(RequestContext ctx, HttpStatus status, String message) {
        requireNonNull(ctx, "ctx");
        requireNonNull(status, "status");
        requireNonNull(message, "message");
        return newResponse0(ctx, status, null, message);
    }
206554
public static function create(
        int $statusCode,
        string $message,
        string $request,
        string $response
    ): ApiClientException {
        switch ($statusCode) {
            case 400:
                $exception = new BadRequestException($message, $request, $response);
                break;
            case 401:
                $exception = new UnauthorizedException($message, $request, $response);
                break;
            case 403:
                $exception = new ForbiddenException($message, $request, $response);
                break;
            case 404:
                $exception = new NotFoundException($message, $request, $response);
                break;
            default:
                $exception = new ApiClientException($message, $statusCode, $request, $response);
                break;
        }
        return $exception;
    }
826896
public function httpError($code, $message = null)
    {
        if ($this->request->isMedia() || !$response = ErrorPage::response_for($code)) {
            parent::httpError($code, $message);
        } else {
            throw new HTTPResponse_Exception($response);
        }
    }
740623
public function iGetAResponseWithAStatusCodeOf($code)
    {
        $actual = $this->getGuzzleResponse()->getStatusCode();

        if ($actual != $code) {
            throw new ClientErrorResponseException(
                'Actual status code ' . $actual . ' does not match expected ' .
                'status code ' . $code . ' with message: ' .
                $this->getGuzzleResponse()->getMessage()
            );
        }
    }
692002
public function setStatusCode(int $statusCode, string $reasonPhrase = null): Response
    {
        $this->status->setCode($statusCode, $reasonPhrase);
        return $this;
    }
684602
public static function respond($status = 404, $message = '') {
        http_response_code($status);
        if (Request::isAjaxRequest()) {
            @header('ajax: 1');
            Response::getInstance()->output(['message' => $message ? $message : __('error occurred')]);
            Response::getInstance()->close();
        } else {
            if ($status == 404) {
                $data ['message'] = $message;
                $view             = template('404.tpl', $data);
            } else if ($status == 403) {
                $data ['message'] = $message;
                $view             = template('403.tpl', $data);
            } else if ($status == 500) {
                $data ['message'] = $message;
                $view             = template('500.tpl', $data);
            } else if ($status == 503) {
                $data ['message'] = $message;
                $view             = template('503.tpl', $data);
            } else if ($message) {
                if (is_array($message)) {
                    $view = new JsonView($message);
                } else {
                    $view = new SimpleView($message);
                }
            } else {
                $view = null;
            }
            if ($view) {
                Response::getInstance()->output($view);
                Response::getInstance()->close();
            }
        }
        exit (1);
    }
1347159
protected function _respondToError($errorMessage, $httpCode) {
        $this->_setHttpStatusCode($httpCode);
        $this->view->result = array(
            'success' => false,
            'errorMessage' => $errorMessage
        );
    }
953060
protected static void error(
            final HttpServletResponse httpServletResponse, final String message, final HttpStatus code) {
        try {
            httpServletResponse.setContentType("text/plain");
            httpServletResponse.setStatus(code.value());
            setNoCache(httpServletResponse);
            try (PrintWriter out = httpServletResponse.getWriter()) {
                out.println("Error while processing request:");
                out.println(message);
            }

            LOGGER.error("Error while processing request: {}", message);
        } catch (IOException ex) {
            throw ExceptionUtils.getRuntimeException(ex);
        }
    }
886351
public function forbidden($msg = '', $errorCode = null, $headers = [])
    {
        return $this->getErrorResponse($msg, $errorCode, self::HTTP_FORBIDDEN, $headers);
    }
626710
public function response($content, int $statusCode = 200, string $statusMessage = 'OK'): Response
    {
        $response = [
            'statusCode' => $statusCode,
            'statusMessage' => $statusMessage,
            'content' => $content,
        ];

        if ($this->config->application->debug->logRequest) {
            $this->log->addInfo('RESPONSE', $response);
        }

        // Create a response since it's an ajax
        //in order to use the current response instead of having to create a new object , this is needed for swoole servers
        $response = $this->response ?? new Response(); 
        $response->setStatusCode($statusCode, $statusMessage);
        $response->setContentType('application/vnd.api+json', 'UTF-8');
        $response->setJsonContent($content);

        return $response;
    }
692845
protected function responseError($body, $httpCode)
    {
        return $this->parseResponse($body) ?: $this->jsonError($body, $httpCode);
    }
448024
public function respondCreated($code = ApiResponse::CODE_SUCCESS, array $data = [], $message = null): JsonResponse
    {
        return $this->setStatusCode(IlluminateResponse::HTTP_CREATED)->respond([
            'status' => [
                'type' => 'success',
                'message' => $this->getDefaultMessage($code, $message),
                'code' => $code,
                'http_code' => $this->getStatusCode(),
            ],
            'data' => $data,
        ]);
    }
1015626
static public function create(
        $httpStatus = Response::HTTP_INTERNAL_SERVER_ERROR,
        $message = '',
        \Exception $previous = null
    ) {
        return new static($httpStatus, $message, $previous);
    }
798620
public function withError($message, $errorCode = 500, array $headers = [])
    {
        $data = [
            'status'  => false,
            'success' => false,
            'code'    => $errorCode ?: $this->getStatusCode(),
            'msg'     => $message,
            'error'   => [
                'code'      => $errorCode,
                'http_code' => $this->statusCode,
                'message'   => $message,
            ],
        ];

        return $this->response($data, $headers);
    }
1034307
protected function respondWithMessage($success = true, $message = '', $code = 0)
    {
        if (!$message) {
            if ($success) {
                $message = rawurlencode(_t(
                    'CMSMain.ACTION_COMPLETE',
                    'Done'
                ));
            } else {
                $message = rawurlencode(_t(
                    'CMSMain.ACTION_FAILED',
                    'Could not complete action'
                ));
            }
        }

        if (!$code) {
            $code = $success ? 200 : 400;
        }

        $this->owner->Response->setStatusCode($code);
        $this->owner->Response->addHeader('X-Status', $message);

        return $this->owner->getResponseNegotiator()->respond($this->owner->Request, [
            'SiteTree' => function () {
            }
        ]);
    }