$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");
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
/**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
\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*/
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)
{