From cb52a4cdc2daa45a61c728f5ec83603e6c6a71fa Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Tue, 3 Feb 2015 00:23:12 +0100 Subject: Rework error handling in upload validator Signed-off-by: Florian Pritz --- index.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'index.php') diff --git a/index.php b/index.php index f41ee5fc5..35fb64313 100644 --- a/index.php +++ b/index.php @@ -299,7 +299,11 @@ register_shutdown_function("check_for_fatal"); * And away we go... * */ -require_once BASEPATH.'core/CodeIgniter.php'; +try { + require_once BASEPATH.'core/CodeIgniter.php'; +} catch (\exceptions\UserInputException $e) { + show_error(nl2br(htmlspecialchars($e->__toString())), 400); +} /* End of file index.php */ /* Location: ./index.php */ -- cgit v1.2.3-24-g4f1b From 9ea78213f8e505b5fde7372106adc1947d1f7de2 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Tue, 3 Feb 2015 11:14:29 +0100 Subject: Improve general exception handling Signed-off-by: Florian Pritz --- index.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'index.php') diff --git a/index.php b/index.php index 35fb64313..21d3ffc04 100644 --- a/index.php +++ b/index.php @@ -249,17 +249,26 @@ function getExceptionTraceAsString($exception) { return $rtn; } +function _log_exception($e) +{ + $backtrace = getExceptionTraceAsString($e); + $log_heading = sprintf("Exception '%s' with message '%s' in %s:%d", get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()); + error_log($log_heading."\n".$backtrace); +} + // The actual exception handler function _actual_exception_handler($e) { + _log_exception($e); + $display_errors = in_array(strtolower(ini_get('display_errors')), array('1', 'on', 'true', 'stdout')); $GLOBALS["is_error_page"] = true; $heading = "Internal Server Error"; $message = "

An unhandled error occured.

\n"; - $backtrace = getExceptionTraceAsString($e); if ($display_errors) { + $backtrace = getExceptionTraceAsString($e); $message .= '
'; $message .= 'Fatal error: Uncaught exception '.get_class($e).'
'; $message .= 'Message: '.$e->getMessage().'
'; @@ -270,9 +279,6 @@ function _actual_exception_handler($e) $message .="

More information can be found in syslog or by enabling display_errors.

"; } - $log_heading = sprintf("Exception '%s' with message '%s' in %s:%d", get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()); - error_log($log_heading."\n".$backtrace); - $message = "$message"; include APPPATH."/errors/error_general.php"; } -- cgit v1.2.3-24-g4f1b From bcd7920b817b60df9b1b266118419e44c39900db Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Tue, 3 Feb 2015 13:59:59 +0100 Subject: generalize authentication handling Signed-off-by: Florian Pritz --- index.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'index.php') diff --git a/index.php b/index.php index 21d3ffc04..051e76de6 100644 --- a/index.php +++ b/index.php @@ -307,8 +307,10 @@ register_shutdown_function("check_for_fatal"); */ try { require_once BASEPATH.'core/CodeIgniter.php'; +} catch (\exceptions\NotAuthenticatedException $e) { + redirect("user/login"); } catch (\exceptions\UserInputException $e) { - show_error(nl2br(htmlspecialchars($e->__toString())), 400); + show_error(nl2br(htmlspecialchars($e->__toString())), $e->get_http_error_code()); } /* End of file index.php */ -- cgit v1.2.3-24-g4f1b From a842392c30e9ef1d1d2bd9b4eb271c3fd23b853f Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Tue, 3 Feb 2015 17:17:27 +0100 Subject: Use exceptions instead of show_error Signed-off-by: Florian Pritz --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'index.php') diff --git a/index.php b/index.php index 051e76de6..ebf1667e6 100644 --- a/index.php +++ b/index.php @@ -309,7 +309,7 @@ try { require_once BASEPATH.'core/CodeIgniter.php'; } catch (\exceptions\NotAuthenticatedException $e) { redirect("user/login"); -} catch (\exceptions\UserInputException $e) { +} catch (\exceptions\PublicApiException $e) { show_error(nl2br(htmlspecialchars($e->__toString())), $e->get_http_error_code()); } -- cgit v1.2.3-24-g4f1b