/** * Handle an error by passing the exception to the registered error handler * @param \Exception $e * @throws \Exception */ private function handleError(\Exception $e) { $eh = $this->getErrorHandler(); try { $representation = $this->representationManager->getDeterminedRepresentation($this->getRequest()); $errorDocument = $representation->getDefaultErrorResponse(); $eh->error($e, 500, $errorDocument); } catch (UnableToMatchRepresentationException $e) { $errorDocument = new ErrorResponseText(); $eh->error($e, 500, $errorDocument); } $this->getResponse()->setStatusCode($eh->getResponseCode()); $this->getResponse()->setHttpHeader('Content-Type', $errorDocument::getContentType()); $this->getResponse()->setBody($errorDocument->render()); }