From: Kevin Day Date: Sat, 3 Feb 2018 06:13:06 +0000 (-0600) Subject: Update: display error messages on server error page X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=ff54dbaa838f7c22c2c6ddcc7eb74eacfdb940f6;p=koopa Update: display error messages on server error page --- diff --git a/common/standard/classes/standard_path.php b/common/standard/classes/standard_path.php index 9c08eb6..d52226e 100644 --- a/common/standard/classes/standard_path.php +++ b/common/standard/classes/standard_path.php @@ -2135,7 +2135,6 @@ class c_standard_path extends c_base_path { return c_theme_html::s_create_tag(c_base_markup_tag::TYPE_LIST_ITEM, $id, $classes); } - /** * Create a new HTML markup class with default settings populated. * @@ -2646,6 +2645,38 @@ class c_standard_path extends c_base_path { } /** + * Converts a given error message into a processed string. + * + * @param c_base_error $code + * The error message code. + * @param bool $arguments + * (optional) When TRUE, argument placeholders are added. + * When FALSE, no placeholders are provided. + * All placeholders should begin with a single colon ':' and be wrapped within '{}', such that 'example' placeholder is ':{example}'. + * @param bool $function_name + * (optional) When TRUE, the function name is included with the message. + * When FALSE, no funciton name is provided. + * @param null|string $additional_message + * (optional) Any additional messages to display. + * @param bool $use_html + * (optional) When TRUE, the message is escaped and then wrapped in HTML. + * When FALSE, no HTML wrapping or escaping is peformed. + * + * @return c_base_return_string + * A processed string is returned on success. + * FALSE with error bit set is returned on error. + * + * @see: s_get_message() + */ + protected function pr_get_error_text($error, $arguments = TRUE, $function_name = FALSE, $additional_message = NULL, $html = FALSE) { + if (!($error instanceof c_base_error)) { + return new c_base_return_false(); + } + + return c_base_return_string::s_new(''); + } + + /** * Load text for a supported language. * * @param int $index diff --git a/common/standard/internal/ja/server_error.php b/common/standard/internal/ja/server_error.php index d9cbe1b..6c03d7b 100644 --- a/common/standard/internal/ja/server_error.php +++ b/common/standard/internal/ja/server_error.php @@ -11,6 +11,18 @@ namespace n_koopa; final class c_standard_path_server_error_ja extends c_standard_path_server_error { /** + * Implements pr_get_error_text(). + */ + protected function pr_get_error_text($error, $arguments = TRUE, $function_name = FALSE, $additional_message = NULL, $html = FALSE) { + if (!($error instanceof c_base_error)) { + return new c_base_return_false(); + } + + require_once('common/base/classes/base_error_messages_japanese.php'); + return c_base_error_messages_japanese::s_render_error_message($error, $arguments, $function_name, $additional_message, $html); + } + + /** * Implements pr_get_text(). */ protected function pr_get_text($code, $arguments = []) { @@ -22,6 +34,9 @@ final class c_standard_path_server_error_ja extends c_standard_path_server_error case 1: $string = 'リクエストの処理中に問題が発生しました。しばらくしてからもう一度お試しください。'; break; + case 2: + $string = 'エラーメッセージ'; + break; } if (!empty($arguments)) { diff --git a/common/standard/internal/server_error.php b/common/standard/internal/server_error.php index ab660da..ba89699 100644 --- a/common/standard/internal/server_error.php +++ b/common/standard/internal/server_error.php @@ -28,6 +28,40 @@ class c_standard_path_server_error extends c_standard_path_exception { $wrapper->set_tag($this->pr_create_tag_text_block(1)); + // append any error messages to the page. + $errors = $this->session->get_error(); + if (is_array($errors) && !empty($errors)) { + $error_wrapper = $this->pr_create_tag_wrapper('error-block'); + $error_wrapper->set_tag($this->pr_create_tag_header(2, 2, 'error-block-title')); + + $error_list = $this->pr_create_tag_list(); + foreach ($errors as $error) { + $error_text = $this->pr_get_error_text($error); + if (!($error_text instanceof c_base_return_string)) { + unset($error_text); + continue; + } + + $text = $this->pr_create_tag_text($error_text->get_value_exact()); + unset($error_text); + + $list_item = $this->pr_create_tag_list_item(); + $list_item->set_tag($text); + unset($text); + + $error_list->set_tag($list_item); + unset($list_item); + } + unset($error); + + $error_wrapper->set_tag($error_list); + unset($error_list); + + $wrapper->set_tag($error_wrapper); + unset($error_wrapper); + } + + // initialize the content as HTML. $this->pr_create_html(FALSE); $this->html->set_tag($wrapper); @@ -72,6 +106,18 @@ class c_standard_path_server_error extends c_standard_path_exception { } /** + * Implements pr_get_error_text(). + */ + protected function pr_get_error_text($error, $arguments = TRUE, $function_name = FALSE, $additional_message = NULL, $html = FALSE) { + if (!($error instanceof c_base_error)) { + return new c_base_return_false(); + } + + require_once('common/base/classes/base_error_messages_english.php'); + return c_base_error_messages_english::s_render_error_message($error, $arguments, $function_name, $additional_message, $html); + } + + /** * Implements pr_get_text(). */ protected function pr_get_text($code, $arguments = []) { @@ -83,6 +129,9 @@ class c_standard_path_server_error extends c_standard_path_exception { case 1: $string = 'Something went wrong while processing your request, please try again later.'; break; + case 2: + $string = 'Error Messages'; + break; } if (!empty($arguments)) {