Drahak\Restful\Application\UI\ResourcePresenter::sendErrorResource PHP Method

sendErrorResource() protected method

Send error resource to output
protected sendErrorResource ( Exception | Throwable $e, $contentType = NULL )
$e Exception | Throwable
    protected function sendErrorResource($e, $contentType = NULL)
    {
        /** @var Request $request */
        $request = $this->getHttpRequest();
        $this->resource = $this->createErrorResource($e);
        // if the $contentType is not forced and the user has requested an unacceptable content-type, default to JSON
        $accept = $request->getHeader('Accept');
        if ($contentType === NULL && (!$accept || !$this->responseFactory->isAcceptable($accept))) {
            $contentType = IResource::JSON;
        }
        try {
            $response = $this->responseFactory->create($this->resource, $contentType);
            $response = new ErrorResponse($response, $e->getCode() > 99 && $e->getCode() < 600 ? $e->getCode() : 400);
            $this->sendResponse($response);
        } catch (InvalidStateException $e) {
            $this->sendErrorResource(BadRequestException::unsupportedMediaType($e->getMessage(), $e), $contentType);
        }
    }