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);
}
}