converted transaction error reporting to exceptions instead of hard exit
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 24 May 2010 16:30:10 +0000 (16:30 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 24 May 2010 16:30:10 +0000 (16:30 +0000)
git-svn-id: https://silmor.de/svn/softmagic/pack/trunk@470 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

phpbase/autoload.php
phpbase/exception.php
phpbase/transaction.php
woc/phpout.cpp

index a7e52de..3498aee 100644 (file)
@@ -17,6 +17,7 @@ $AUTOCLASS["WobTable"]= $d."/table.php";
 $AUTOCLASS["WobSchemaBase"]=$d."/schema.php";
 $AUTOCLASS["WobTransactionBase"]=$d."/transaction.php";
 $AUTOCLASS["WobXmlException"]=$d."/exception.php";
+$AUTOCLASS["WobTransactionError"]=$d."/exception.php";
 $AUTOCLASS["WObject"]=$d."/object.php";
 //load the linguist dummies, since we use them quite often
 include_once($d."/tr.php");
index 732ac74..f41c026 100644 (file)
 
 class WobXmlException extends Exception {};
 
+/**general Wob Error - thrown whenever a transaction fails for any reason*/
+class WobTransactionError extends Exception
+{
+       protected $etype="_system";
+       protected $estr="";
+       
+       public function __construct($errorString,$errorType="_system")
+       {
+               parent::__construct($errorString);
+               $this->etype=$errorType;
+               $this->estr=$errorString;
+       }
+       
+       /**used by machine oriented transaction to print the proper XML representation of the error*/
+       public function printXml()
+       {
+               header("X-WobResponse-Status: Error");
+               print("<WobError type=\"".xq($this->etype)."\">".xq($this->estr)."</WobError>\n");
+       }
+       
+       /**returns the error type*/
+       public function errorType(){return $this->etype;}
+       
+       /**returns the error string*/
+       public function errorString(){return $this->estr;}
+       
+};
+
 ?>
\ No newline at end of file
index da46df1..c3feaef 100644 (file)
@@ -51,34 +51,29 @@ class WobTransactionBase {
        /**called if the transaction is not known. aborts the script.*/
        static public function noSuchTransaction()
        {
-               header("X-WobResponse-Status: Error");
-               print("<WobError type=\"non-wob\">".tr("Request is not known, Aborting.")."</WobError>\n");
                $this->abortTransaction();
-               exit();
+               throw new WobTransactionError(tr("Request is not known, Aborting."),"non-wob");
        }
        
        /**called if authentication fails*/
        public function notAuthenticated(){
-               header("X-WobResponse-Status: Error");
-               print("<WobError type=\"auth\">".tr("User is not authenticated or does not have permission to execute this request, Aborting.")."</WobError>\n");
                $this->abortTransaction();
-               exit();
+               throw new WobTransactionError(tr("User is not authenticated or does not have permission to execute this request, Aborting."),"auth");
        }
        
        /**called if XML parsing fails*/
        public function xmlParserError(){
-               header("X-WobResponse-Status: Error");
-               print("<WobError type=\"xml\">".tr("Error while parsing request XML, Aborting.")."</WobError>\n");
                $this->abortTransaction();
-               exit();
+               throw new WobTransactionError(tr("Error while parsing request XML, Aborting."),"xml");
        }
        
        /**called for generic exception handling*/
        public function handleException($ex){
-               header("X-WobResponse-Status: Error");
-               print("<WobError type=\"exception\">".xq($ex->getMessage())."</WobError>\n");
+               //throw on, if it already is internal
+               if(is_a($ex,"WobTransactionError"))
+                       throw $ex;
                $this->abortTransaction();
-               exit();
+               throw new WobTransactionError($ex->getMessage(),"exception");
        }
        
        /**called to abort a transactions flow
@@ -86,10 +81,8 @@ class WobTransactionBase {
        \param $text the human readable text returned to the client
        */
        public function abortWithError($text,$type="server"){
-               header("X-WobResponse-Status: Error");
-               print("<WobError type=\"".xq($type)."\">".xq($text)."</WobError>\n");
                $this->abortTransaction();
-               exit();
+               throw new WobTransactionError($text,$type);
        }
        
        /**called internally if a transaction is not implemented*/
index 82e2deb..55801e8 100644 (file)
@@ -22,8 +22,8 @@ static const QByteArray SCHEMASTART("class WobSchema extends WobSchemaBase\n{\nf
 static const QByteArray SCHEMAEND("}};\n");
 
 static const QByteArray TRANSACTCLASS("class WobTransaction extends WobTransactionBase\n{\n");
-static const QByteArray TRANSACTSTART("  static public function handle(){switch(WobTransactionBase::getTransactionName()){\n");
-static const QByteArray TRANSACTEND("\tdefault:WobTransactionBase::noSuchTransaction();break;\n  }}\n");
+static const QByteArray TRANSACTSTART("  static public function handle(){\n    try{switch(WobTransactionBase::getTransactionName()){\n");
+static const QByteArray TRANSACTEND("\tdefault:WobTransactionBase::noSuchTransaction();break;\n    }}catch(WobTransactionError $er){$er->printXml();}\n  }\n");
 
 WocPHPServerOut::WocPHPServerOut(const QDomElement&el)
 {