GitList
Repositories
Help
Report an Issue
vroom360
Code
Commits
Branches
Tags
Search
Tree:
e36c40f
Branches
Tags
master
vroom360
ErrorObject.php
initial commit
Dev Ghai
commited
e36c40f
at 2013-09-26 06:24:15
ErrorObject.php
Blame
History
Raw
<?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * Description of errors * * @author dghai */ require_once 'Config.php'; require_once 'RequestObject.php'; require_once 'Dao.php'; define('E_VROOM_INSERT_FAILED', -7); define('E_VROOM_EXECUTE_QUERY_FAILED', -6); define('E_VROOM_PREPARE_QUERY_FAILED', -5); define('E_VROOM_LOAD_RECV_PRI_KEY_FAILED', -4); define('E_VROOM_LOAD_SEND_PUB_KEY_FAILED', -3); define('E_VROOM_INVALID_FUNCTION_CALL', -2); define('E_VROOM_DB_CONNECT_FAILED', -1); define('E_VROOM_LOGIN_FAILED', 1); $allErrorDescriptions = array( E_VROOM_INSERT_FAILED => 'There was error inserting data into the database.', E_VROOM_EXECUTE_QUERY_FAILED => 'There was an error executing the query.', E_VROOM_PREPARE_QUERY_FAILED => 'Mysqli had problems with preparing the statement to send to DB.', E_VROOM_LOAD_RECV_PRI_KEY_FAILED => 'There was an error loading private key to decrypt data.', E_VROOM_LOAD_SEND_PUB_KEY_FAILED => 'Loading public key to encrypt data before sending to iPad... failed. Anyway, what\'s up?', E_VROOM_INVALID_FUNCTION_CALL => 'An invalid function call was made. Expected number of parameters were not delivered.', E_VROOM_DB_CONNECT_FAILED => 'Could not connect to the database with the given credentials.', E_VROOM_LOGIN_FAILED => 'ACCESS_DENIED', ); class ErrorObject { public $errorCode; public $errorDescription; private $_config; function __construct($communicationObject, $errorCode, $errorDescription = '') { global $allErrorDescriptions; $this->errorCode = $errorCode; if($errorDescription != '') $this->errorDescription = $errorDescription; else $this->errorDescription = $allErrorDescriptions[$errorCode]; $this->_config = new Config(); $this->LogError($communicationObject, $errorCode); } private function LogError($commObj, $errorCode) { if(!$this->_config->IsSavingErrorToDbEnabled()) { return; } $request = $commObj instanceof RequestObject? $commObj->ToJSONString() : $commObj; if($errorCode == E_VROOM_DB_CONNECT_FAILED) { //TODO: Log $request to file or server's error log return; } //TODO: Log $request error to DB } } ?>