/** * Statically Process Frapi Errors * * This method will process the FRAPI Errors, pass them to the * output handler, and format it correctly. * * This method is in fact a hack. Whenever we instantiate the controller * object from the source — index.php in this case — we can't try and * catch the same controller object because the exception might in fact * be thrown directly from within the constructor thus invalidating * and sending the self $controller object out of scope. Thence this hack * that instantiates it's own controller, ignores the exception thrown * * This also allows us to catch syntax errors before the constructor * is invoked and allows us to handle the errors gracefully. * * @param Frapi_Exception $e The frapi exception to use * @return object The response object. */ public static function processInternalError(Frapi_Exception $e) { try { $controller = new Frapi_Controller_Api(); return $controller->getOutputInstance($controller->getFormat())->setOutputAction('defaultError')->populateOutput($e->getErrorArray())->sendHeaders($e)->executeOutput(); } catch (Exception $e) { // This is a hack to intercept anything that may // have happened before the internal error collection // during the initialisation process. // // If we got here, we have no controller and cannot properly handle // output, so we just send a 500 and die. header("HTTP/1.0 500 Internal Server Error"); exit; } }
/** * Statically Process Frapi Errors * * This method will process the FRAPI Errors, pass them to the * output handler, and format it correctly. * * This method is in fact a hack. Whenever we instantiate the controller * object from the source — index.php in this case — we can't try and * catch the same controller object because the exception might in fact * be thrown directly from within the constructor thus invalidating * and sending the self $controller object out of scope. Thence this hack * that instantiates it's own controller, ignores the exception thrown * * This also allows us to catch syntax errors before the constructor * is invoked and allows us to handle the errors gracefully. * * @param Frapi_Exception $e The frapi exception to use * @return object The response object. */ public static function processInternalError(Frapi_Exception $e) { try { $controller = new Frapi_Controller_Api(); return $controller->getOutputInstance($controller->getFormat())->setOutputAction('defaultError')->populateOutput($e->getErrorArray())->sendHeaders($e)->executeOutput(); } catch (Frapi_Error $e) { // If it's just a Frapi_Error, we want to rethrow it. throw $e; } catch (Exception $e) { // We have no controller or error handler, // so send some indication somewhere that things went wrong. ob_start(); debug_print_backtrace(); error_log(ob_get_clean()); header("HTTP/1.0 500 Internal Server Error"); exit; } }
/** * Statically Process Frapi Errors * * This method will process the FRAPI Errors, pass them to the * output handler, and format it correctly. * * This method is in fact a hack. Whenever we instantiate the controller * object from the source — index.php in this case — we can't try and * catch the same controller object because the exception might in fact * be thrown directly from within the constructor thus invalidating * and sending the self $controller object out of scope. Thence this hack * that instantiates it's own controller, ignores the exception thrown * * This also allows us to catch syntax errors before the constructor * is invoked and allows us to handle the errors gracefully. * * @param Frapi_Exception $e The frapi exception to use * @return object The response object. */ public static function processInternalError(Frapi_Exception $e) { try { $controller = new Frapi_Controller_Api(); } catch (Exception $e) { // This is a hack to intercept anything that may // have happened before the internal error collection // during the initialisation process. } return $controller->getOutputInstance($controller->getFormat())->setOutputAction('defaultError')->populateOutput($e->getErrorArray())->sendHeaders($e)->executeOutput(); }