/**
  * Nice singleton, lets us grab the renderer part way through execution if the errorHandler kicks in
  */
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         $c = __CLASS__;
         self::$instance = new $c();
     }
     return self::$instance;
 }
Example #2
0
 function testErrorRender()
 {
     $result = new error("wrms_fail does not exist");
     $response_renderer = response_renderer::getInstance();
     $response_renderer->set_format('xml');
     $xml = $response_renderer->render($result);
     $xml = preg_replace('!\\s!', '', $xml);
     $correct = preg_replace('!\\s!', '', "<error><status><message>wrms_fail does not exist</message><code>400</code></status><data></data></error>");
     if (!$this->assertEqual($correct, $xml)) {
         //what we g
         $this->dump('I got this: ' . $xml);
         $this->dump('I expected this: ' . $correct);
     }
 }
Example #3
0
function errorHandler($errno, $errstr, $errfile, $errline)
{
    switch ($errno) {
        /*
         * If we hit an actual error
         */
        case E_ERROR:
        case E_CORE_ERROR:
        case E_COMPILE_ERROR:
        case E_USER_ERROR:
        case E_RECOVERABLE_ERROR:
            error_logging('ERROR', $errstr . ' in ' . $errfile . ' on line ' . $errline);
            $response_renderer = response_renderer::getInstance();
            $error = new error($errstr, 500);
            echo $response_renderer->render($error);
            exit;
            break;
        case E_WARNING:
        case E_CORE_WARNING:
        case E_COMPILE_WARNING:
        case E_USER_WARNING:
            error_logging('WARNING', $errstr . ' in ' . $errfile . ' on line ' . $errline);
            $error_array = explode(' ', $errstr);
            $response_renderer = response_renderer::getInstance();
            /*
             * As we hit errors, we should add nice explainations here
             */
            switch ($error_array[0]) {
                case 'pg_query()':
                    $errstr = 'An error occured with a database query, please try again. If the issue persists, please contact support';
                    break;
            }
            $error = new error($errstr, 500);
            echo $response_renderer->render($error);
            exit;
            break;
        default:
            return false;
            break;
    }
    return true;
}
Example #4
0
 */
/**
 * @file 
 * Every request goes through this file
 * 
 * e.g. http://api.wrms.com/wrms.get
 * 
 */
require_once 'medusa/common.php';
$params = array('GET' => array(), 'POST' => array());
$uri = $_SERVER['REQUEST_URI'];
$Uri_Parser = new Uri_Parser($uri);
$method = $Uri_Parser->get_method();
$params['GET'] = $Uri_Parser->get_params();
$format = $Uri_Parser->get_format();
$response_renderer = response_renderer::getInstance();
error_logging('DEBUG', "method={$method} params=" . print_r($params, true) . " format={$format}");
/*
 * POST variables are not cleaned here
 */
#foreach ($_POST as $k => $v) {
$params['POST'] = $_POST;
#}
if (!$method) {
    error_logging('ERROR', "No method");
    echo $response_renderer->render(new error("Method required"));
    exit(0);
} elseif (!$format) {
    error_logging('ERROR', "No format");
    echo $response_renderer->render(new error("Format required"));
    exit(0);