better fatal error handling by frontend (remove error.php)
This commit is contained in:
parent
6e7f8d269e
commit
af106b0ebe
19
backend.php
19
backend.php
|
@ -21,11 +21,16 @@
|
|||
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 "<error error-code=\"6\"/>";
|
||||
print_error_xml(6); die;
|
||||
} else {
|
||||
print "
|
||||
<html><body>
|
||||
|
@ -54,15 +59,9 @@
|
|||
}
|
||||
|
||||
if (!$op) {
|
||||
print "<error error-code=\"7\"/>";
|
||||
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",
|
||||
|
|
88
error.php
88
error.php
|
@ -1,88 +0,0 @@
|
|||
<?
|
||||
require_once "sanity_check.php";
|
||||
require_once "version.php";
|
||||
require_once "config.php";
|
||||
require_once "db-prefs.php";
|
||||
|
||||
$ERRORS[0] = "Unknown error";
|
||||
|
||||
$ERRORS[1] = "This program requires XmlHttpRequest " .
|
||||
"to function properly. Your browser doesn't seem to support it.";
|
||||
|
||||
$ERRORS[2] = "This program requires cookies " .
|
||||
"to function properly. Your browser doesn't seem to support them.";
|
||||
|
||||
$ERRORS[3] = "Backend sanity check failed.";
|
||||
|
||||
$ERRORS[4] = "Frontend sanity check failed.";
|
||||
|
||||
$ERRORS[5] = "Incorrect database schema version.";
|
||||
|
||||
$ERRORS[6] = "Not authorized.";
|
||||
|
||||
if ($_GET["c"] == 6) {
|
||||
header("Location: login.php");
|
||||
}
|
||||
|
||||
$ERRORS[7] = "No operation to perform.";
|
||||
|
||||
$ERRORS[8] = "Could not display feed: query failed. Please check label match syntax or local configuration.";
|
||||
|
||||
$ERRORS[8] = "Denied. Your access level is insufficient to access this page.";
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Tiny Tiny RSS : Error Message</title>
|
||||
|
||||
<link rel="stylesheet" href="tt-rss.css" type="text/css">
|
||||
|
||||
<!--[if gte IE 5.5000]>
|
||||
<script type="text/javascript" src="pngfix.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
</head>
|
||||
|
||||
<table width="100%" height="100%" cellspacing="0" cellpadding="0" class="main">
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<table cellspacing="0" cellpadding="0" width="100%"><tr>
|
||||
<td class="header" valign="middle">
|
||||
<img src="images/ttrss_logo.png" alt="logo">
|
||||
</td>
|
||||
<td align="right" valign="top">
|
||||
<div id="notify"><span id="notify_body"></div>
|
||||
</td>
|
||||
</tr></table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td id="prefContent" class="prefContent" valign="top" colspan="2">
|
||||
|
||||
<h1>Fatal Error</h1>
|
||||
|
||||
<div class="bigErrorMsg"><?= $ERRORS[$_GET["c"]] ?>
|
||||
|
||||
<? if ($_GET["p"]) { ?>
|
||||
<p><?= htmlspecialchars($_GET["p"]) ?></p>
|
||||
<? } ?>
|
||||
</div>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="footer" colspan="2">
|
||||
<a href="http://bah.spb.su/~fox/tt-rss/">Tiny-Tiny RSS</a> v<?= VERSION ?> © 2005 Andrew Dolgov
|
||||
<? if (WEB_DEMO_MODE) { ?>
|
||||
<br>Running in demo mode, some functionality is disabled.
|
||||
<? } ?>
|
||||
</td>
|
||||
</td>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<?
|
||||
$ERRORS[0] = "Unknown error";
|
||||
|
||||
$ERRORS[1] = "This program requires XmlHttpRequest " .
|
||||
"to function properly. Your browser doesn't seem to support it.";
|
||||
|
||||
$ERRORS[2] = "This program requires cookies " .
|
||||
"to function properly. Your browser doesn't seem to support them.";
|
||||
|
||||
$ERRORS[3] = "Backend sanity check failed";
|
||||
|
||||
$ERRORS[4] = "Frontend sanity check failed.";
|
||||
|
||||
$ERRORS[5] = "Incorrect database schema version.";
|
||||
|
||||
$ERRORS[6] = "Request not authorized.";
|
||||
|
||||
$ERRORS[7] = "No operation to perform.";
|
||||
|
||||
$ERRORS[8] = "Could not display feed: query failed. Please check label match syntax or local configuration.";
|
||||
|
||||
$ERRORS[8] = "Denied. Your access level is insufficient to access this page.";
|
||||
|
||||
$ERRORS[9] = "Configuration check failed";
|
||||
?>
|
|
@ -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", "");
|
||||
|
||||
|
|
|
@ -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 "<error error-code=\"$code\" error-msg=\"$error_msg\"/>";
|
||||
}
|
||||
?>
|
||||
|
|
26
tt-rss.css
26
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;
|
||||
}
|
||||
|
|
29
tt-rss.js
29
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 = "<li>[" + ts + "] " + msg + "</li>" + 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,10 @@
|
|||
<body>
|
||||
|
||||
<div id="overlay"><div id="overlay_inner">Loading, please wait...</div></div>
|
||||
<div id="fatal_error"><div id="fatal_error_inner">
|
||||
<h1>Fatal Error</h1>
|
||||
<pre id="fatal_error_msg">Unknown Error</pre>
|
||||
</div></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
if (document.addEventListener) {
|
||||
|
|
Loading…
Reference in New Issue