Exemplo n.º 1
0
 public static function handleException(Exception $exception)
 {
     // Call Bugsnag
     Bugsnag::exceptionHandler($exception);
     // Fall back to Cake..
     return parent::handleException($exception);
 }
Exemplo n.º 2
0
 public function renderFile()
 {
     header("Content-Type: application/json;charset=utf-8");
     $aRequest = array();
     $sContentType = 'application/x-www-form-urlencoded';
     if (isset($_SERVER['CONTENT_TYPE'])) {
         $sContentType = $_SERVER['CONTENT_TYPE'];
     }
     if (isset($_SERVER['HTTP_CONTENT_TYPE'])) {
         $sContentType = $_SERVER['HTTP_CONTENT_TYPE'];
     }
     if (StringUtil::startsWith($sContentType, 'application/json')) {
         $aRequest = json_decode(file_get_contents('php://input'), true);
     } else {
         foreach ($_REQUEST as $sKey => $sValue) {
             $aRequest[$sKey] = json_decode($sValue, true);
         }
     }
     $oSession = Session::getSession();
     if (!isset($aRequest['session_language']) && $oSession->isAuthenticated()) {
         $aRequest['session_language'] = $oSession->getUser()->getLanguageId();
     }
     $sPrevSessionLanguage = null;
     $sSetSessionLanguage = null;
     if (isset($aRequest['session_language'])) {
         $sPrevSessionLanguage = Session::language();
         $sSetSessionLanguage = $aRequest['session_language'];
         $oSession->setLanguage($sSetSessionLanguage);
     }
     try {
         try {
             $mJSONData = $this->getJSON($aRequest);
             $sResult = json_encode($mJSONData);
             $iError = json_last_error();
             if ($iError !== JSON_ERROR_NONE) {
                 throw new LocalizedException('wns.error.json', array('json_error' => $iError, 'json_error_message' => self::$JSON_ERRORS[$iError]));
             }
             print $sResult;
         } catch (Exception $e) {
             //Handle the gift, not the wrapping…
             if ($e->getPrevious()) {
                 throw $e->getPrevious();
             } else {
                 throw $e;
             }
         }
     } catch (LocalizedException $ex) {
         LinkUtil::sendHTTPStatusCode(500, 'Server Error');
         print json_encode(array('exception' => array('message' => $ex->getLocalizedMessage(), 'code' => $ex->getCode(), 'file' => $ex->getFile(), 'line' => $ex->getLine(), 'trace' => $ex->getTrace(), 'parameters' => $ex->getMessageParameters(), 'exception_type' => $ex->getExceptionType())));
     } catch (Exception $ex) {
         LinkUtil::sendHTTPStatusCode(500, 'Server Error');
         ErrorHandler::handleException($ex, true);
         print json_encode(array('exception' => array('message' => "Exception when trying to execute the last action {$ex->getMessage()}", 'code' => $ex->getCode(), 'file' => $ex->getFile(), 'line' => $ex->getLine(), 'trace' => $ex->getTrace(), 'exception_type' => get_class($ex))));
     }
     //If we changed the session language and no widget willfully changed it as well, reset it to the previous state
     if ($sPrevSessionLanguage !== null && Session::language() === $sSetSessionLanguage) {
         $oSession->setLanguage($sPrevSessionLanguage);
     }
 }
 /**
  * This method will handle any Exception thrown.
  *
  * @param Exception $exception The exception to be handled
  *
  * @return void
  */
 public static function handle($exception)
 {
     // Verify if the debug level is at least the minDebugLevel
     if (Configure::read('debug') >= self::$minDebugLevel) {
         // Debug level is high enough, use the Whoops handler
         $Whoops = new Whoops\Run();
         $Whoops->pushHandler(new Whoops\Handler\PrettyPageHandler());
         $Whoops->handleException($exception);
     } else {
         // Debug level is too low, fall back to CakePHP default ErrorHandler
         ErrorHandler::handleException($exception);
     }
 }
Exemplo n.º 4
0
 public static function handleException(Exception $exception)
 {
     try {
         // Avoid bot scan errors
         if (Configure::read('Sentry.avoid_bot_scan_errors') && ($exception instanceof MissingControllerException || $exception instanceof MissingPluginException) && Configure::read('debug') == 0) {
             echo Configure::read('Sentry.avoid_bot_scan_errors');
             exit(0);
         }
         self::sentryLog($exception);
         return parent::handleException($exception);
     } catch (Exception $e) {
         return parent::handleException($e);
     }
 }
Exemplo n.º 5
0
 /**
  * This method will be executed to set up the error handlers
  *
  * @static
  * @access public
  * @return void
  */
 private static function initErrorHandlers()
 {
     set_exception_handler(function ($e) {
         require_once 'ErrorHandler.php';
         ErrorHandler::handleException($e);
     });
     set_error_handler(function ($code, $error, $file, $line) {
         require_once 'ErrorHandler.php';
         ErrorHandler::handleNormalError($code, $error, $file, $line);
     });
     register_shutdown_function(function () {
         require_once 'ErrorHandler.php';
         ErrorHandler::handleShutdown();
     });
 }
Exemplo n.º 6
0
 public static function handleException(Exception $exception)
 {
     //MissingControllerException 方法的一般都是无效的访问,丢出去
     if ($exception instanceof MissingControllerException || $exception instanceof MissingActionException || $exception instanceof MissingViewException) {
         header("HTTP/1.0 404 Not Found");
         echo "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>404 Not Found</title></head><body><div align=\"center\"><a href=\"/\"><img src=\"/img/button/404.gif\" border=\"0\" /></a></div></body></html>";
         exit;
     }
     $config = Configure::read('Exception');
     if (@$config['log']) {
         $slow_log = "";
         $slow_log .= "\nHTTP_HOST  http://" . @(@$_SERVER['HTTP_X_REAL_HOST'] ? @$_SERVER['HTTP_X_REAL_HOST'] : $_SERVER['HTTP_HOST']) . @$_SERVER["REQUEST_URI"];
         $slow_log .= "\nHTTP_REFERER= " . @$_SERVER["HTTP_REFERER"];
         $slow_log .= "\nHTTP_USER_AGENT= " . @$_SERVER["HTTP_USER_AGENT"];
         $slow_log .= "\nSCRIPT_FILENAME= " . @$_SERVER["SCRIPT_FILENAME"];
         $slow_log .= var_export(@$_POST, true);
         $slow_log .= var_export(@$_GET, true);
         CakeLog::write(LOG_ERR, $slow_log);
     }
     parent::handleException($exception);
 }
Exemplo n.º 7
0
 public function getPageData()
 {
     $oPage = PageQuery::create()->findPk($this->iPageId);
     $aResult = $oPage->toArray(BasePeer::TYPE_PHPNAME, false);
     // addition related page fields
     $aResult['PageLink'] = LinkUtil::absoluteLink(LinkUtil::link($oPage->getFullPathArray(), 'FrontendManager', array(), AdminManager::getContentLanguage()), null, 'auto');
     $aResult['PageHref'] = LinkUtil::absoluteLink(LinkUtil::link($oPage->getFullPathArray(), 'FrontendManager', array(), AdminManager::getContentLanguage()), null, 'default', true);
     // page properties are displayed if added to template
     try {
         $mAvailableProperties = $this->getAvailablePageProperties($oPage);
         if (count($mAvailableProperties) > 0) {
             $aResult['page_properties'] = $mAvailableProperties;
         }
     } catch (Exception $e) {
         ErrorHandler::handleException($e, true);
     }
     // page references are displayed if exist
     $mReferences = AdminModule::getReferences(ReferencePeer::getReferences($oPage));
     $aResult['CountReferences'] = count($mReferences);
     if ($mReferences !== null) {
         $aResult['page_references'] = $mReferences;
     }
     return $aResult;
 }
Exemplo n.º 8
0
 /**
  * test handleException generating a page.
  *
  * @return void
  */
 function testHandleExceptionLog()
 {
     if ($this->skipIf(file_exists(APP . 'app_error.php'), 'App error exists cannot run.')) {
         return;
     }
     if (file_exists(LOGS . 'error.log')) {
         unlink(LOGS . 'error.log');
     }
     Configure::write('Exception.log', true);
     $error = new NotFoundException('Kaboom!');
     ob_start();
     ErrorHandler::handleException($error);
     $result = ob_get_clean();
     $this->assertPattern('/Kaboom!/', $result, 'message missing.');
     $log = file(LOGS . 'error.log');
     $this->assertPattern('/\\[NotFoundException\\] Kaboom!/', $log[0], 'message missing.');
     $this->assertPattern('/\\#0.*ErrorHandlerTest->testHandleExceptionLog/', $log[1], 'Stack trace missing.');
 }
#!/usr/bin/env php
<?php 
require_once __DIR__ . '/../../../base/lib/inc.php';
try {
    set_error_handler(array('ErrorHandler', "handleError"));
    foreach (LanguageQuery::create()->filterByIsActive(true)->find() as $oLanguage) {
        $sLanguageId = $oLanguage->getId();
        $oModule = new UpdateSearchIndexFileModule(array(), $sLanguageId, true);
        $oModule->renderFile();
    }
} catch (Exception $oException) {
    ErrorHandler::handleException($oException);
}
Exemplo n.º 10
0
 public static function handleException(Exception $exception)
 {
     $errbitCake = new ErrbitCakePHP();
     $errbitCake->onException($exception);
     return parent::handleException($exception);
 }
Exemplo n.º 11
0
 /**
  * @see ErrorHandler::handleException
  */
 public static function handleException($exception)
 {
     // Check if the exception is not in the `ignoredExceptions` array
     $ignoredExceptions = Configure::read('Sentry.ignoredExceptions');
     if (!$ignoredExceptions) {
         $ignoredExceptions = array();
     }
     $className = get_class($exception);
     $eventId = true;
     if (!in_array($className, $ignoredExceptions)) {
         $eventId = self::sentryCapture($exception);
     }
     if ($eventId !== null) {
         parent::handleException($exception);
     }
 }
Exemplo n.º 12
0
 public static function handle($error, $message = null)
 {
     $SeoAppError = new SeoAppError();
     if ($error->code == 404) {
         $SeoAppError->catch404();
         $SeoAppError->runLevenshtein();
     }
     $text = $message ? $message : $error->message;
     ErrorHandler::handleException($error);
 }
 public static function handleException($e)
 {
     ErrorHandler::handleException($e);
 }
Exemplo n.º 14
0
 public static function handleException(Exception $exception)
 {
     self::bugsnagHandleException($exception);
     return parent::handleException($exception);
 }
Exemplo n.º 15
0
<?php

namespace DYuriev;

/*
* @author: Dmitriy Yuriev <*****@*****.**>
* @product: error_handler
* @version: 1.1.1
* @release date: 27.07.2014
* @development started: 15.07.2014
* @license: GNU AGPLv3 <http://www.gnu.org/licenses/agpl.txt>
*
* A small useful library that helps to handle PHP fatal errors and exceptions.
* Supports messages on two languages: russian and english.
*/
error_reporting(-1);
ini_set("display_errors", "Off");
ini_set("display_startup_errors", "Off");
ini_set("html_errors", "Off");
define('ERROR_HANDLER_DIR', __DIR__);
require_once ERROR_HANDLER_DIR . '/class/ErrorHandler.class.php';
$error_handler = new ErrorHandler(\Swift_Mailer::newInstance(\Swift_MailTransport::newInstance()), \Swift_Message::newInstance());
set_error_handler(function ($err_no, $err_str, $err_file, $err_line) use($error_handler) {
    $error_handler->handleError($err_no, $err_str, $err_file, $err_line);
}, E_ALL | E_STRICT);
set_exception_handler(function ($exception) use($error_handler) {
    $error_handler->handleException($exception);
});
register_shutdown_function(function () use($error_handler) {
    $error_handler->handleShutdown();
});
Exemplo n.º 16
0
 public static function handle($error, $message = null)
 {
     $SeoAppError = new SeoAppError();
     $SeoAppError->catch404();
     if ($error->code == 404) {
         $SeoAppError->runLevenshtein();
     }
     $text = $message ? $message : $error->message;
     CakeLog::write('error' . $error->code, $text . '\\n\\r' . $error->getTraceAsString());
     ErrorHandler::handleException($error);
 }
Exemplo n.º 17
0
 public function testHandleException()
 {
     $this->assertNull(ErrorHandler::handleException(new ErrorHandlerTestException()));
 }
Exemplo n.º 18
0
 /**
  * tests it is possible to load a plugin exception renderer
  *
  * @return void
  */
 public function testLoadPluginHandler()
 {
     App::build(array('Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)), App::RESET);
     CakePlugin::load('TestPlugin');
     Configure::write('Exception.renderer', 'TestPlugin.TestPluginExceptionRenderer');
     $error = new NotFoundException('Kaboom!');
     ob_start();
     ErrorHandler::handleException($error);
     $result = ob_get_clean();
     $this->assertEquals('Rendered by test plugin', $result);
     CakePlugin::unload();
 }
 public static function handleException(Exception $exception)
 {
     static::getBugsnag()->exceptionHandler($exception);
     return parent::handleException($exception);
 }