Sketch for catching exceptions

This is required in order to catch exceptions that get triggered during
the rendering
This commit is contained in:
Dennis Eichhorn 2016-07-12 17:11:41 +02:00
parent 73cee286a1
commit 401e251f4c

View File

@ -117,25 +117,12 @@ class Response extends ResponseAbstract implements RenderableInterface
{ {
switch ($this->header->get('Content-Type')) { switch ($this->header->get('Content-Type')) {
case MimeType::M_JSON: case MimeType::M_JSON:
return $this->getJson(); return $this->jsonSerialize();
default: default:
return $this->getRaw(); return $this->getRaw();
} }
} }
/**
* Generate json response.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
private function getJson() : string
{
return json_encode($this->toArray());
}
/** /**
* Generate raw response. * Generate raw response.
* *
@ -173,6 +160,7 @@ class Response extends ResponseAbstract implements RenderableInterface
{ {
$result = []; $result = [];
try {
foreach ($this->response as $key => $response) { foreach ($this->response as $key => $response) {
if ($response instanceof View) { if ($response instanceof View) {
$result += $response->toArray(); $result += $response->toArray();
@ -186,9 +174,14 @@ class Response extends ResponseAbstract implements RenderableInterface
throw new \Exception('Wrong response type'); throw new \Exception('Wrong response type');
} }
} }
} catch(\Exception $e) {
// todo: handle exception
// need to to try catch for logging. otherwise the json_encode in the logger will have a problem with this
$result = [];
} finally {
return $result; return $result;
} }
}
/** /**
* {@inheritdoc} * {@inheritdoc}