/**
* @param \Exception $exception
*
* @return string
*/
public function format(\Exception $exception)
{
$response = new Response();
try {
$response = $this->serialize($this->config->isDebug() ? new Entity\DebugError($exception) : new Entity\Error($exception), is_null($this->request) ? Request::createFromGlobals() : $this->request, $response);
} catch (\Exception $e) {
$response->setContent($this->serviceHateoas()->getSerializer()->serialize($this->config->isDebug() ? new Entity\DebugError($e) : new Entity\Error($e), 'json'));
$vendor = $this->getContainer()->get(Application::CONTAINER_ID_VENDOR);
$apiVersion = $this->getContainer()->get(Application::CONTAINER_ID_API_VERSION);
$response->headers->set('Content-Type', 'application/vnd.' . $vendor . '-v' . $apiVersion . '+json');
}
$response->setStatusCode(method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : 500);
$response->sendHeaders();
return $response->getContent();
}