From af106b0ebe0b34189a83bbfb64e9c9ace044a273 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 31 Mar 2006 06:18:55 +0100 Subject: [PATCH] better fatal error handling by frontend (remove error.php) --- backend.php | 19 ++++++----- error.php | 88 --------------------------------------------------- errors.php | 25 +++++++++++++++ functions.js | 9 ------ functions.php | 12 +++++++ tt-rss.css | 26 +++++++++++++++ tt-rss.js | 29 ++++++++++++++--- tt-rss.php | 4 +++ 8 files changed, 101 insertions(+), 111 deletions(-) delete mode 100644 error.php create mode 100644 errors.php diff --git a/backend.php b/backend.php index 5554adae2..df3e7d036 100644 --- a/backend.php +++ b/backend.php @@ -20,12 +20,17 @@ require_once "sanity_check.php"; require_once "config.php"; + + require_once "db.php"; + require_once "db-prefs.php"; + require_once "functions.php"; + require_once "magpierss/rss_fetch.inc"; $err_msg = check_configuration_variables(); if ($err_msg) { - print "Fatal error: $err_msg"; - exit; + header("Content-Type: application/xml"); + print_error_xml(9, $err_msg); die; } if ((!$op || $op == "rpc" || $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) { @@ -35,7 +40,7 @@ if (!$_SESSION["uid"] && $op != "globalUpdateFeeds") { if ($op == "rpc") { - print ""; + print_error_xml(6); die; } else { print " @@ -54,15 +59,9 @@ } if (!$op) { - print ""; - exit; + print_error_xml(7); exit; } - require_once "db.php"; - require_once "db-prefs.php"; - require_once "functions.php"; - require_once "magpierss/rss_fetch.inc"; - $purge_intervals = array( 0 => "Default", -1 => "Never purge", diff --git a/error.php b/error.php deleted file mode 100644 index 8c5a6a4b5..000000000 --- a/error.php +++ /dev/null @@ -1,88 +0,0 @@ - - - - - Tiny Tiny RSS : Error Message - - - - - - - - - - - - - - - - - - -
- - - -
- logo - -
-
-
- -

Fatal Error

- -
- - -

- -
- -
- - - - - - diff --git a/errors.php b/errors.php new file mode 100644 index 000000000..556af0882 --- /dev/null +++ b/errors.php @@ -0,0 +1,25 @@ + diff --git a/functions.js b/functions.js index 9858608ca..99efbcbac 100644 --- a/functions.js +++ b/functions.js @@ -574,15 +574,6 @@ function hideOrShowFeeds(doc, hide) { } -function fatalError(code, params) { - if (!params) { - window.location = "error.php?c=" + param_escape(code); - } else { - window.location = "error.php?c=" + param_escape(code) + - "&p=" + param_escape(params); - } -} - function selectTableRow(r, do_select) { r.className = r.className.replace("Selected", ""); diff --git a/functions.php b/functions.php index 14d9fa154..d4feaf5d6 100644 --- a/functions.php +++ b/functions.php @@ -9,6 +9,7 @@ require_once 'config.php'; require_once 'db-prefs.php'; require_once 'compat.php'; + require_once 'errors.php'; require_once 'magpierss/rss_utils.inc'; @@ -1498,4 +1499,15 @@ return $version[1]; } + function print_error_xml($code, $add_msg = "") { + global $ERRORS; + + $error_msg = $ERRORS[$code]; + + if ($add_msg) { + $error_msg = "$error_msg; $add_msg"; + } + + print ""; + } ?> diff --git a/tt-rss.css b/tt-rss.css index 39d4083f9..be1f5cb88 100644 --- a/tt-rss.css +++ b/tt-rss.css @@ -1052,3 +1052,29 @@ div.cdmContent a:hover { text-align : center; margin : 10px; } + +#fatal_error { + background : white; + left : 0; + top : 0; + height : 100%; + width : 100%; + z-index : 200; + display : none; + position : absolute; +} + +#fatal_error_inner { + font-weight : bold; + margin : 10px; + color : red; +} + +#fatal_error_msg { + border : 1px solid #c0c0c0; + background-color : #f0f0f0; + width : 50%; + color : black; + padding : 10px; + font-weight : normal; +} diff --git a/tt-rss.js b/tt-rss.js index 06f9fadc0..6ad0adff7 100644 --- a/tt-rss.js +++ b/tt-rss.js @@ -124,7 +124,7 @@ function refetch_callback() { var error_code = reply.getAttribute("error-code"); if (error_code && error_code != 0) { - return fatalError(error_code); + return fatalError(error_code, reply.getAttribute("error-msg")); } var f_document = window.frames["feeds-frame"].document; @@ -153,21 +153,21 @@ function backend_sanity_check_callback() { try { if (!xmlhttp.responseXML) { - fatalError(3, "D001: " + xmlhttp.responseText); + fatalError(3, "[D001, Reply is not XML]: " + xmlhttp.responseText); return; } var reply = xmlhttp.responseXML.firstChild; if (!reply) { - fatalError(3, "D002: " + xmlhttp.responseText); + fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText); return; } var error_code = reply.getAttribute("error-code"); if (error_code && error_code != 0) { - return fatalError(error_code); + return fatalError(error_code, reply.getAttribute("error-msg")); } debug("sanity check ok"); @@ -697,3 +697,24 @@ function debug(msg) { c.innerHTML = "
  • [" + ts + "] " + msg + "
  • " + c.innerHTML; } } + +function fatalError(code, message) { +/* if (!params) { + window.location = "error.php?c=" + param_escape(code); + } else { + window.location = "error.php?c=" + param_escape(code) + + "&p=" + param_escape(params); + } */ + + try { + var fe = document.getElementById("fatal_error"); + var fc = document.getElementById("fatal_error_msg"); + + fc.innerHTML = "Code " + code + ": " + message; + + fe.style.display = "block"; + + } catch (e) { + exception_error("fatalError", e); + } +} diff --git a/tt-rss.php b/tt-rss.php index 2906241ab..71a866c68 100644 --- a/tt-rss.php +++ b/tt-rss.php @@ -62,6 +62,10 @@
    Loading, please wait...
    +
    +

    Fatal Error

    +
    Unknown Error
    +