mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-10 05:58:42 +00:00
Sketch for catching exceptions
This is required in order to catch exceptions that get triggered during the rendering
This commit is contained in:
parent
73cee286a1
commit
401e251f4c
|
|
@ -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,21 +160,27 @@ class Response extends ResponseAbstract implements RenderableInterface
|
||||||
{
|
{
|
||||||
$result = [];
|
$result = [];
|
||||||
|
|
||||||
foreach ($this->response as $key => $response) {
|
try {
|
||||||
if ($response instanceof View) {
|
foreach ($this->response as $key => $response) {
|
||||||
$result += $response->toArray();
|
if ($response instanceof View) {
|
||||||
} elseif (is_array($response)) {
|
$result += $response->toArray();
|
||||||
$result += $response;
|
} elseif (is_array($response)) {
|
||||||
} elseif (is_scalar($response)) {
|
$result += $response;
|
||||||
$result[] = $response;
|
} elseif (is_scalar($response)) {
|
||||||
} elseif ($response instanceof \Serializable) {
|
$result[] = $response;
|
||||||
$result[] = $response->serialize();
|
} elseif ($response instanceof \Serializable) {
|
||||||
} else {
|
$result[] = $response->serialize();
|
||||||
throw new \Exception('Wrong response type');
|
} else {
|
||||||
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user