Index: /sandbox/webservice/api/adapters/ExpressoAdapter.php
===================================================================
--- /sandbox/webservice/api/adapters/ExpressoAdapter.php	(revision 6149)
+++ /sandbox/webservice/api/adapters/ExpressoAdapter.php	(revision 6165)
@@ -100,6 +100,8 @@
 		if($this->getResult())
 			$body['result']	= $this->getResult();
-		else
-			throw new ResponseException("",Errors::E_UNKNOWN_ERROR);
+		else {
+			Errors::runException("E_UNKNOWN_ERROR");			
+		}
+		
 		
 		$response->body = json_encode($body);
@@ -115,9 +117,9 @@
 			}
 			else{
-				throw new ResponseException("",Errors::LOGIN_AUTH_INVALID);
+				Errors::runException("LOGIN_AUTH_INVALID");							
 			}
 		}
 		else{
-			throw new ResponseException("",Errors::LOGIN_NOT_LOGGED_IN);
+			Errors::runException("LOGIN_NOT_LOGGED_IN");			
 		}		
 	}	
Index: /sandbox/webservice/api/library/utils/Errors.php
===================================================================
--- /sandbox/webservice/api/library/utils/Errors.php	(revision 6165)
+++ /sandbox/webservice/api/library/utils/Errors.php	(revision 6165)
@@ -0,0 +1,50 @@
+<?php
+
+final class Errors {
+		
+	private static $sInstance;
+	private $errors;
+	
+	public static function getInstance(){
+		if (!self::$sInstance) {
+			self::$sInstance = new Errors();
+		}
+		return self::$sInstance;
+	}
+	
+	function __construct(){
+		$this->errors = array();
+		if($handle = fopen(__DIR__."/../../config/Errors.tsv", "r")){	
+			while (!feof($handle)) {
+				$line = trim(fgets($handle,1024));
+				if($line == null || $line[0] == "#")
+					continue;
+				$error = preg_split("/[\t]+/", $line);
+				if(is_array($error)&& count($error) == 3) {
+					$this->errors[] = array("code" => $error[0], "key" => $error[1], "message" => $error[2]);
+				}
+			}
+		}	
+	}
+	
+	static public function runException($needle, $argument = false){		
+		$error = false;
+		$type = (is_int($needle) ? "code" : "key");
+		foreach( Errors::getInstance()->errors as $value ){
+			if($value[$type] == $needle){
+				$error = $value;
+				break;
+			}
+		}
+		
+		if($error['message'] && $argument){
+			$error['message'] = str_replace("%1", $argument, $error['message']);
+		}		
+		if(!$error){
+			Errors::getInstance()->runException("E_UNKNOWN_ERROR");
+		}		
+		
+		throw new ResponseException($error['message'], $error['code']);		 
+	}	
+		
+}
Index: /sandbox/webservice/api/config/Errors.tsv
===================================================================
--- /sandbox/webservice/api/config/Errors.tsv	(revision 6165)
+++ /sandbox/webservice/api/config/Errors.tsv	(revision 6165)
@@ -0,0 +1,35 @@
+# Errors from -32000 to -32099 => Server error: Reserved for implementation-defined server-errors.
+
+-32700		E_PARSE_ERROR					Parse error
+-32600		E_INVALID_REQUEST				Invalid Request
+-32601		E_METHOD_NOT_FOUND				Method not found
+-32602		E_INVALID_PARAMS				Invalid params
+-32603		E_INTERNAL_ERROR				Internal error
+404			E_HTTP_NOT_FOUND				A resource matching URI '%1' was not found
+500			E_UNKNOWN_ERROR					HTTP Unknown error
+
+# Errors inherited from Expresso Application.
+1			LOGIN_SUCCESS_LOGOUT			You have been successfully logged out
+2			LOGIN_SESSION_EXPIRED			Sorry, your login has expired
+3			LOGIN_NOT_LOGGED_IN				You are not logged in
+4			LOGIN_COOKIES_REQUIRED			Cookies are required to login to this site.
+5			LOGIN_BADLOGIN					bad login or password
+6			LOGIN_PASSWORD_EXPIRED			Your password has expired, and you do not have access to change it
+7			LOGIN_AUTH_INVALID				Your auth is invalid
+10			LOGIN_SESSION_NOT_VERIFIED		Your session could not be verified.
+98			LOGIN_ACCOUNT_EXPIRED			Account is expired
+99			LOGIN_LOGIN_BLOCKED				Blocked, too many attempts!
+200			LOGIN_INVALID_LOGIN				Bad login or password
+
+1001		CATALOG_MIN_ARGUMENT_SEARCH		Your search argument must be longer than %1 characters.
+1002		MAIL_NOT_SENT					Your mail could not be sent.
+1003		MAIL_TRASH_NOT_CLEANED			Your trash folder could not be cleaned.
+1004		MAIL_MESSAGE_NOT_FOUND			Message not found in folder %1.
+1005		MAIL_INVALID_NEW_FOLDER_NAME	Invalid folder name.
+1006 		MAIL_INVALID_OLD_FOLDER			Invalid old folder.
+1007 		MAIL_INVALID_FOLDER				Invalid folder.
+1008		MAIL_CANNOT_DEL_DEFAULT_FOLDER	Cannot delete a default folder.
+1009		MAIL_FOLDER_NOT_EMPTY			The folder is not empty.
+1010		MAIL_FOLDER_NOT_RENAMED			The folder could not be renamed.
+1011		MAIL_FOLDER_NOT_ADDED			The folder could not be added.
+1012		MAIL_FOLDER_NOT_DELETED			The folder could not be deleted.
Index: /sandbox/webservice/api/rest/mail/RenameFolderResource.php
===================================================================
--- /sandbox/webservice/api/rest/mail/RenameFolderResource.php	(revision 6155)
+++ /sandbox/webservice/api/rest/mail/RenameFolderResource.php	(revision 6165)
@@ -12,12 +12,12 @@
 
 			if(!$this->getImap()->folder_exists($old_id))
-				throw new ResponseException("",Errors::MAIL_INVALID_OLD_FOLDER);
+				Errors::runException("MAIL_INVALID_OLD_FOLDER");
 
 			$default_folders = array_keys($this->defaultFolders);
 			if(in_array($old_id, $default_folders))
-				throw new ResponseException("",Errors::MAIL_INVALID_OLD_FOLDER);
+				Errors::runException("MAIL_INVALID_OLD_FOLDER");
 
 			if(empty($new_name) || preg_match('/[\/\\\!\@\#\$\%\&\*\(\)]/', $new_name))
-				throw new ResponseException("",Errors::MAIL_INVALID_NEW_FOLDER_NAME);
+				Errors::runException("MAIL_INVALID_NEW_FOLDER_NAME");
 
 			$old_id_arr = explode($this->getImap()->imap_delimiter, $old_id);
@@ -30,5 +30,5 @@
 			$result = $this->getImap()->ren_mailbox($params);
 			if($result != 'Ok')
-				throw new ResponseException("",Errors::MAIL_FOLDER_NOT_RENAMED);
+				Errors::runException("MAIL_FOLDER_NOT_RENAMED");
 		}
 
Index: /sandbox/webservice/api/rest/mail/AddFolderResource.php
===================================================================
--- /sandbox/webservice/api/rest/mail/AddFolderResource.php	(revision 6155)
+++ /sandbox/webservice/api/rest/mail/AddFolderResource.php	(revision 6165)
@@ -13,5 +13,5 @@
 
 			if(empty($new_name) || preg_match('/[\/\\\!\@\#\$\%\&\*\(\)]/', $new_name))
-				throw new ResponseException("",Errors::MAIL_INVALID_NEW_FOLDER_NAME);
+				Errors::runException("MAIL_INVALID_NEW_FOLDER_NAME");
 
 			$new_id = $parent_id . $this->getImap()->imap_delimiter . $new_name;
@@ -21,5 +21,5 @@
 			$result = $this->getImap()->create_mailbox($params);
 			if($result != 'Ok')
-				throw new ResponseException("",Errors::MAIL_FOLDER_NOT_ADDED);
+				Errors::runException("MAIL_FOLDER_NOT_ADDED");
 		}
 
Index: /sandbox/webservice/api/rest/mail/CleanTrashResource.php
===================================================================
--- /sandbox/webservice/api/rest/mail/CleanTrashResource.php	(revision 6148)
+++ /sandbox/webservice/api/rest/mail/CleanTrashResource.php	(revision 6165)
@@ -10,5 +10,5 @@
 			$params['clean_folder'] = 'imapDefaultTrashFolder';
 			if(!$this -> getImap() -> empty_folder($params))
-				throw new ResponseException("",Errors::MAIL_TRASH_NOT_CLEANED);
+				Errors::runException("MAIL_TRASH_NOT_CLEANED");
 		}
 
Index: /sandbox/webservice/api/rest/mail/MessagesResource.php
===================================================================
--- /sandbox/webservice/api/rest/mail/MessagesResource.php	(revision 6148)
+++ /sandbox/webservice/api/rest/mail/MessagesResource.php	(revision 6165)
@@ -12,6 +12,5 @@
 				$msg = $this->getMessage();
 				if(!$msg){
-					$error = Errors::get(Errors::MAIL_MESSAGE_NOT_FOUND, $this->getParam('folderID'));
-					throw new ResponseException($error['message'], $error['code']);
+					Errors::runException("MAIL_MESSAGE_NOT_FOUND", $this->getParam('folderID'));
 				}
 				else{
Index: /sandbox/webservice/api/rest/mail/SendSupportFeedbackResource.php
===================================================================
--- /sandbox/webservice/api/rest/mail/SendSupportFeedbackResource.php	(revision 6148)
+++ /sandbox/webservice/api/rest/mail/SendSupportFeedbackResource.php	(revision 6165)
@@ -29,5 +29,5 @@
 
 			if (!$returncode || !(is_array($returncode) && $returncode['success'] == true))
-				throw new ResponseException("",Errors::MAIL_NOT_SENT);
+				Errors::runException("MAIL_NOT_SENT");
 		}
 
Index: /sandbox/webservice/api/rest/mail/DelFolderResource.php
===================================================================
--- /sandbox/webservice/api/rest/mail/DelFolderResource.php	(revision 6155)
+++ /sandbox/webservice/api/rest/mail/DelFolderResource.php	(revision 6165)
@@ -11,9 +11,9 @@
 
 			if(!$this->getImap()->folder_exists($folder_id))
-				throw new ResponseException("",Errors::MAIL_INVALID_FOLDER);
+				Errors::runException("MAIL_INVALID_FOLDER");
 
 			$default_folders = array_keys($this->defaultFolders);
 			if(in_array($folder_id, $default_folders))
-				throw new ResponseException("",Errors::MAIL_CANNOT_DEL_DEFAULT_FOLDER);
+				Errors::runException("MAIL_CANNOT_DEL_DEFAULT_FOLDER");
 
 			$personal_folders = $this->getImap()->get_folders_list(array('noSharedFolders' => true, 'folderType' => 'personal'));
@@ -23,13 +23,13 @@
 			foreach($personal_folders AS $personal_folder){
 				if($personal_folder['folder_id'] == $folder_id && $personal_folder['folder_hasChildren'])
-					throw new ResponseException("",Errors::MAIL_FOLDER_NOT_EMPTY);
+					Errors::runException("MAIL_FOLDER_NOT_EMPTY");
 			}
 
 			if($this->getImap()->get_num_msgs(array('folder' => $folder_id)) > 0)
-				throw new ResponseException("",Errors::MAIL_FOLDER_NOT_EMPTY);
+				Errors::runException("MAIL_FOLDER_NOT_EMPTY");
 
 			$result = $this->getImap()->delete_mailbox($params);
 			if($result != 'Ok')
-				throw new ResponseException("",Errors::MAIL_FOLDER_NOT_DELETED);
+				Errors::runException("MAIL_FOLDER_NOT_DELETED");
 		}
 
Index: /sandbox/webservice/api/rest/dispatch.php
===================================================================
--- /sandbox/webservice/api/rest/dispatch.php	(revision 6155)
+++ /sandbox/webservice/api/rest/dispatch.php	(revision 6165)
@@ -2,6 +2,6 @@
 
 // load libraries
-require_once __DIR__.'/../library/tonic/lib/tonic.php'; 
-require_once(__DIR__."/../Errors.php");
+require_once(__DIR__.'/../library/tonic/lib/tonic.php'); 
+require_once(__DIR__.'/../library/utils/Errors.php');
 
 // load adapters
@@ -54,5 +54,13 @@
 			break;
 		default:
-			$response = Errors::getResponse($request, $e);
+			
+			$response = new Response($request);
+			$response->code = Response::OK;
+			$response->addHeader('content-type', 'application/json');
+			if($request->id)
+				$body['id']	= $request->id;
+			
+			$body['error'] = array("code" => "".$e->getCode(), "message" => $e->getMessage());
+			$response->body = json_encode($body);
 	}
 }
Index: /sandbox/webservice/api/rest/core/LoginResource.php
===================================================================
--- /sandbox/webservice/api/rest/core/LoginResource.php	(revision 6149)
+++ /sandbox/webservice/api/rest/core/LoginResource.php	(revision 6165)
@@ -35,5 +35,5 @@
 		else
 		{
-			throw new ResponseException("",$GLOBALS['phpgw']->session->cd_reason);
+			Errors::runException($GLOBALS['phpgw']->session->cd_reason);
 		}
 		return $this->getResponse();
Index: /sandbox/webservice/api/rest/catalog/ContactsResource.php
===================================================================
--- /sandbox/webservice/api/rest/catalog/ContactsResource.php	(revision 6148)
+++ /sandbox/webservice/api/rest/catalog/ContactsResource.php	(revision 6165)
@@ -24,6 +24,5 @@
 						return $this->getGlobalContacts($search, $this->getParam('contactID'));
 					else{
-						$error = Errors::get(Errors::CATALOG_MIN_ARGUMENT_SEARCH, $this-> getMinArgumentSearch());						
-						throw new ResponseException($error['message'], $error['code']);
+						Errors::runException("CATALOG_MIN_ARGUMENT_SEARCH", $this-> getMinArgumentSearch());
 					}
 				}
Index: ndbox/webservice/api/Errors.php
===================================================================
--- /sandbox/webservice/api/Errors.php	(revision 6155)
+++ 	(revision )
@@ -1,112 +1,0 @@
-<?php
-
-final class Errors {
-		
-	// Errors from -32000 to -32099 => Server error	:Reserved for implementation-defined server-errors.
-	const E_PARSE_ERROR 		= "-32700";	
-	const E_INVALID_REQUEST 	= "-32600";
-	const E_METHOD_NOT_FOUND 	= "-32601";
-	const E_INVALID_PARAMS 		= "-32602";
-	const E_INTERNAL_ERROR 		= "-32603";	
-
-	const E_HTTP_NOT_FOUND		= "404";
-	const E_UNKNOWN_ERROR		= "500";
-	
-	
-	// Errors inherited from Expresso Application.	
-	const LOGIN_SUCCESS_LOGOUT 			= "1";
-	const LOGIN_SESSION_EXPIRED 		= "2";
-	const LOGIN_NOT_LOGGED_IN 			= "3";
-	const LOGIN_COOKIES_REQUIRED 		= "4";
-	const LOGIN_BADLOGIN 				= "5";
-	const LOGIN_PASSWORD_EXPIRED 		= "6";
-	const LOGIN_AUTH_INVALID 			= "7";
-	const LOGIN_SESSION_NOT_VERIFIED 	= "10";
-	const LOGIN_ACCOUNT_EXPIRED 		= "98";
-	const LOGIN_LOGIN_BLOCKED 			= "99";
-	const LOGIN_INVALID_LOGIN 			= "200";
-	
-
-	const CATALOG_MIN_ARGUMENT_SEARCH		= "1001";
-	const MAIL_NOT_SENT						= "1002";
-	const MAIL_TRASH_NOT_CLEANED			= "1003";
-	const MAIL_MESSAGE_NOT_FOUND			= "1004";
-	const MAIL_INVALID_NEW_FOLDER_NAME		= "1005";
-	const MAIL_INVALID_OLD_FOLDER			= "1006";
-	const MAIL_INVALID_FOLDER				= "1007";
-	const MAIL_CANNOT_DEL_DEFAULT_FOLDER	= "1008";
-	const MAIL_FOLDER_NOT_EMPTY				= "1009";
-	const MAIL_FOLDER_NOT_RENAMED			= "1010";
-	const MAIL_FOLDER_NOT_ADDED				= "1011";
-	const MAIL_FOLDER_NOT_DELETED			= "1012";
-	
-	static private $reservedErrors = array (			
-		self::E_PARSE_ERROR 		=> "Parse error",
-		self::E_INVALID_REQUEST 	=> "Invalid Request",
-		self::E_METHOD_NOT_FOUND 	=> "Method not found",
-		self::E_INVALID_PARAMS 		=> "Invalid params",
-		self::E_INTERNAL_ERROR		=> "Internal error",
-		self::E_HTTP_NOT_FOUND		=> 'A resource matching URI "%1" was not found',
-		self::E_UNKNOWN_ERROR		=> "HTTP Unknown error"
-	);
-	
-	
-	// Errors inherited from Expresso Application.
-	static private $applicationErrors = array(			
-
-		self::LOGIN_SUCCESS_LOGOUT				=> "You have been successfully logged out",
-		self::LOGIN_SESSION_EXPIRED				=> "Sorry, your login has expired",
-		self::LOGIN_NOT_LOGGED_IN				=> "You are not logged in",
-		self::LOGIN_COOKIES_REQUIRED			=> "Cookies are required to login to this site.",
-		self::LOGIN_BADLOGIN					=> "bad login or password",
-		self::LOGIN_PASSWORD_EXPIRED	 		=> "Your password has expired, and you do not have access to change it",
-		self::LOGIN_AUTH_INVALID				=> "Your auth is invalid",
-		self::LOGIN_SESSION_NOT_VERIFIED		=> "Your session could not be verified.",
-		self::LOGIN_ACCOUNT_EXPIRED				=> "Account is expired",
-		self::LOGIN_LOGIN_BLOCKED				=> "Blocked, too many attempts!",
-		self::LOGIN_INVALID_LOGIN				=> "Bad login or password",
-		self::CATALOG_MIN_ARGUMENT_SEARCH		=> "Your search argument must be longer than %1 characters.",
-		self::MAIL_NOT_SENT						=> "Your mail could not be sent.",
-		self::MAIL_TRASH_NOT_CLEANED			=> "Your trash folder could not be cleaned.",
-		self::MAIL_MESSAGE_NOT_FOUND			=> "Message not found in folder %1.",
-		self::MAIL_INVALID_NEW_FOLDER_NAME		=> "Invalid folder name.",
-		self::MAIL_INVALID_OLD_FOLDER			=> "Invalid old folder.",
-		self::MAIL_INVALID_FOLDER				=> "Invalid folder.",
-		self::MAIL_CANNOT_DEL_DEFAULT_FOLDER	=> "Cannot delete a default folder.",
-		self::MAIL_FOLDER_NOT_EMPTY				=> "The folder is not empty.",
-		self::MAIL_FOLDER_NOT_RENAMED			=> "The folder could not be renamed.",
-		self::MAIL_FOLDER_NOT_ADDED				=> "The folder could not be added.",
-		self::MAIL_FOLDER_NOT_DELETED			=> "The folder could not be deleted."
-	);
-		
-	static public function set($code, $message){
-		return array ("code" => $code, "message" => $message);
-	}
-
-	static public function get($code, $argument = false){
-		$errors = self::$reservedErrors + self::$applicationErrors;		
-		$message = $errors[$code];
-		if(!$message)
-			$message = $errors[self::E_UNKNOWN_ERROR];
-		if($argument)
-			$message = str_replace("%1", $argument, $message);		
-		
-		return array ("code" => $code, "message" => $message); 
-	}
-	
-	static public function getResponse($request, $responseException){			
-			$response = new Response($request);
-			$response->code = Response::OK;
-			$response->addHeader('content-type', 'application/json');
-			if($request->id)
-				$body['id']	= $request->id;
-			
-			$code	 = $responseException->getCode();
-			$error = Errors::get($code);			
-			$message = ($responseException->getMessage() ? $responseException->getMessage() : $error['message']);			
-			$body['error'] = array("code" => "$code", "message" => $message);		
-			$response->body = json_encode($body);
-			return $response;
-	}
-		
-}
