Improve exception handling

If there is an exception in the template handling then a white page is shown.
This improves the handling of this and shows text only about the internal
error.

To test this just setup redis as cache and then disable the php-redis module.

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
pull/6643/head
Morris Jobke 2017-09-26 11:21:39 +07:00
parent ef3e8faea2
commit 11c31e94fe
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
2 changed files with 13 additions and 1 deletions

@ -47,7 +47,16 @@ try {
OC_Template::printExceptionErrorPage($ex); OC_Template::printExceptionErrorPage($ex);
} catch (\OC\HintException $ex) { } catch (\OC\HintException $ex) {
OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
OC_Template::printErrorPage($ex->getMessage(), $ex->getHint()); try {
OC_Template::printErrorPage($ex->getMessage(), $ex->getHint());
} catch (Exception $ex2) {
\OC::$server->getLogger()->logException($ex, array('app' => 'index'));
\OC::$server->getLogger()->logException($ex2, array('app' => 'index'));
//show the user a detailed error page
OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
OC_Template::printExceptionErrorPage($ex);
}
} catch (\OC\User\LoginException $ex) { } catch (\OC\User\LoginException $ex) {
OC_Response::setStatus(OC_Response::STATUS_FORBIDDEN); OC_Response::setStatus(OC_Response::STATUS_FORBIDDEN);
OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage()); OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage());

@ -331,6 +331,9 @@ class Log implements ILogger {
'Line' => $exception->getLine(), 'Line' => $exception->getLine(),
); );
$data['Trace'] = preg_replace('!(' . implode('|', $this->methodsWithSensitiveParameters) . ')\(.*\)!', '$1(*** sensitive parameters replaced ***)', $data['Trace']); $data['Trace'] = preg_replace('!(' . implode('|', $this->methodsWithSensitiveParameters) . ')\(.*\)!', '$1(*** sensitive parameters replaced ***)', $data['Trace']);
if ($exception instanceof HintException) {
$data['Hint'] = $exception->getHint();
}
$msg = isset($context['message']) ? $context['message'] : 'Exception'; $msg = isset($context['message']) ? $context['message'] : 'Exception';
$msg .= ': ' . json_encode($data); $msg .= ': ' . json_encode($data);
$this->log($level, $msg, $context); $this->log($level, $msg, $context);