/** * 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; } }
/** * Process Frapi Errors * * This method will process the FRAPI Errors, pass them to the * output handler, and format it correctly. * * @param Frapi_Exception $e The frapi exception to use * @return object The response object. */ public function processError(Frapi_Exception $e) { return Frapi_Controller_Api::processInternalError($e); }
<?php require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'library/Frapi/AllFiles.php'; set_error_handler(array('Frapi_Error', 'errorHandler'), E_ALL); try { $controller = new Frapi_Controller_API(); try { $controller->authorize(); echo $controller->processAction()->processOutput(); } catch (Frapi_Exception $e) { echo $controller->processError($e); exit; } catch (Frapi_Error $e) { echo $controller->processError($e); exit; } catch (Exception $e) { echo $controller->processError(new Frapi_Error($e)); exit; } } catch (Frapi_Exception $e) { // Whenever we get here, something went terribly wrong // in the core of FRAPI during initialisation phase. echo Frapi_Controller_Api::processInternalError($e); } catch (Exception $e) { echo Frapi_Controller_Api::processInternalError(new Frapi_Error($e)); }
/** * 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(); } 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(); }
<?php require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'library/Frapi/AllFiles.php'; set_error_handler(array('Frapi_Error', 'errorHandler'), E_ALL); ini_set('zlib.output_compression', 1); try { if (!isset($customAuthorization)) { $customAuthorization = null; } $controller = new Frapi_Controller_Api($customAuthorization); try { $controller->authorize(); echo $controller->processAction()->processOutput(); } catch (Frapi_Exception $e) { echo $controller->processError($e); exit; } catch (Frapi_Error $e) { echo $controller->processError($e); exit; } catch (Exception $e) { echo $controller->processError(new Frapi_Error($e)); exit; } } catch (Frapi_Exception $e) { // Whenever we get here, something went terribly wrong // in the core of FRAPI during initialisation phase. echo Frapi_Controller_Api::processInternalError($e); } catch (Exception $e) { echo Frapi_Controller_Api::processInternalError(new Frapi_Error($e)); }