changeset 210:cafc05949a19

Work on error handling.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 17 Nov 2013 20:35:52 +0200
parents 3870601c17c3
children 5bae42020034
files admajax.php majax.php msitegen.inc.php register.inc.php
diffstat 4 files changed, 21 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/admajax.php	Sun Nov 17 20:20:54 2013 +0200
+++ b/admajax.php	Sun Nov 17 20:35:52 2013 +0200
@@ -505,11 +505,20 @@
     break;
 }
 
+if ($errorSet && !$statusSet)
+  stSetStatus(902, "Error");
 
 if ($statusSet)
-  
+{
+  http_response_code($statusSet);
+  header("Status: ".$statusSet." ".$statusMsg);
+}
   
 if ($errorSet)
-  echo $errorMsg;
+{
+  echo "Following errors occured:\n";
+  foreach ($errorMsgs as $msg)
+    echo " - ".$msg."\n";
+}
 
 ?>
\ No newline at end of file
--- a/majax.php	Sun Nov 17 20:20:54 2013 +0200
+++ b/majax.php	Sun Nov 17 20:35:52 2013 +0200
@@ -69,7 +69,7 @@
       if (req.status == 902)
       {
         statusMsg(req.statusText);
-        alert("Error", req.responseText);
+        alert(req.responseText);
       }
       else
       if (req.status == 200)
--- a/msitegen.inc.php	Sun Nov 17 20:20:54 2013 +0200
+++ b/msitegen.inc.php	Sun Nov 17 20:35:52 2013 +0200
@@ -7,7 +7,7 @@
 
 // Globals and definitions
 $errorSet = FALSE;
-$errorMsg = "";
+$errorMsgs = array();
 $statusSet = 0;
 $statusMsg = "";
 
@@ -34,9 +34,9 @@
 
 function stError($msg)
 {
-  global $errorSet, $errorMsg;
+  global $errorSet, $errorMsgs;
   $errorSet = TRUE;
-  $errorMsg .= "<li>".$msg."</li>\n";
+  $errorMsgs[] = $msg;
 }
 
 
--- a/register.inc.php	Sun Nov 17 20:20:54 2013 +0200
+++ b/register.inc.php	Sun Nov 17 20:35:52 2013 +0200
@@ -170,7 +170,12 @@
   {
     echo
       "<p>Following errors occured:</p>\n".
-      "<ul>\n".$errorMsg."</ul>\n";
+      "<ul>\n";
+
+    foreach ($errorMsgs as $msg)
+      echo " <li>".$msg."</li>\n";
+    
+    echo "</ul>\n";
     stPrintFormData("Go back", "start", array("botcheck"));
   }
   else