public function sendException($exception)
 {
     if (!$this->isErrorFromBot()) {
         $recipients = Config::get("error-emailer::to");
         if (isset($recipients['address'])) {
             // this is a single recipient
             if ($recipients['address']) {
                 $recipients = array($recipients);
             } else {
                 $recipients = array();
             }
         }
         if (sizeof($recipients) > 0) {
             if ($exception instanceof FlattenException) {
                 $flattened = $exception;
             } else {
                 $flattened = FlattenException::create($exception);
             }
             $handler = new ExceptionHandler();
             $content = $handler->getContent($flattened);
             $model = array('trace' => $content, 'exception' => $exception, 'flattened' => $flattened);
             Mail::send(Config::get("error-emailer::error_template"), $model, function ($message) use($model, $recipients) {
                 $subject = View::make(Config::get("error-emailer::subject_template"), $model)->render();
                 $message->subject($subject);
                 foreach ($recipients as $to) {
                     $message->to($to['address'], $to['name']);
                 }
             });
         }
     }
 }
 /**
  * Display the given exception to the user.
  *
  * @param  \Exception  $exception
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function display(Exception $exception)
 {
     if ($this->returnJson) {
         return new JsonResponse(array('error' => $exception->getMessage(), 'file' => $exception->getFile(), 'line' => $exception->getLine()), 500);
     }
     return $this->symfony->createResponse($exception);
 }
 public function testConfigure()
 {
     $logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $userHandler = function () {
     };
     $listener = new DebugHandlersListener($userHandler, $logger);
     $xHandler = new ExceptionHandler();
     $eHandler = new ErrorHandler();
     $eHandler->setExceptionHandler(array($xHandler, 'handle'));
     $exception = null;
     set_error_handler(array($eHandler, 'handleError'));
     set_exception_handler(array($eHandler, 'handleException'));
     try {
         $listener->configure();
     } catch (\Exception $exception) {
     }
     restore_exception_handler();
     restore_error_handler();
     if (null !== $exception) {
         throw $exception;
     }
     $this->assertSame($userHandler, $xHandler->setHandler('var_dump'));
     $loggers = $eHandler->setLoggers(array());
     $this->assertArrayHasKey(E_DEPRECATED, $loggers);
     $this->assertSame(array($logger, LogLevel::INFO), $loggers[E_DEPRECATED]);
 }
Example #4
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function render($request, Exception $e)
 {
     $e = FlattenException::create($e);
     $handler = new SymfonyExceptionHandler(env('APP_DEBUG', false));
     $decorated = $this->decorate($handler->getContent($e), $handler->getStylesheet($e));
     return Response::create($decorated, $e->getStatusCode(), $e->getHeaders());
 }
Example #5
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     switch (get_class($e)) {
         case "Swift_TransportException":
         case "PDOException":
             $errorView = "errors.500_config";
             break;
         case "ErrorException":
             $errorView = "errors.500";
             break;
         case "Symfony\\Component\\HttpKernel\\Exception\\MethodNotAllowedHttpException":
             return abort(400);
         default:
             $errorView = false;
             break;
     }
     if ($errorView) {
         // This makes use of a Symfony error handler to make pretty traces.
         $SymfonyDisplayer = new SymfonyDisplayer(config('app.debug'));
         $FlattenException = FlattenException::create($e);
         $SymfonyCss = $SymfonyDisplayer->getStylesheet($FlattenException);
         $SymfonyHtml = $SymfonyDisplayer->getContent($FlattenException);
         $response = response()->view($errorView, ['exception' => $e, 'error_class' => get_class($e), 'error_css' => $SymfonyCss, 'error_html' => $SymfonyHtml], 500);
         return $this->toIlluminateResponse($response, $e);
     } else {
         return parent::render($request, $e);
     }
 }
 public function testNestedExceptions()
 {
     $handler = new ExceptionHandler(true);
     ob_start();
     $handler->sendPhpResponse(new \RuntimeException('Foo', 0, new \RuntimeException('Bar')));
     $response = ob_get_clean();
     $this->assertStringMatchesFormat('%A<span class="exception_message">Foo</span>%A<span class="exception_message">Bar</span>%A', $response);
 }
 protected function handleWithSymfony(Exception $exception)
 {
     if (!$exception instanceof FlattenException) {
         $exception = FlattenException::create($exception);
     }
     $handler = new ExceptionHandler($this->debug);
     return Response::create($handler->getHtml($exception), $exception->getStatusCode(), $exception->getHeaders());
 }
Example #8
0
 public function onSilexError(GetResponseForExceptionEvent $event)
 {
     if (!$this->enabled) {
         return;
     }
     $handler = new DebugExceptionHandler($this->debug);
     $event->setResponse($handler->createResponse($event->getException()));
 }
Example #9
0
 /**
  * Convert an exception to a response
  *
  * @param \Exception $exception
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function handleException($exception)
 {
     if (!$exception instanceof FlattenException) {
         $exception = FlattenException::create($exception);
     }
     $handler = new BaseExceptionHandler($this->debug);
     $decorated = $this->decorate($handler->getContent($exception), $handler->getStylesheet($exception));
     return new Response($decorated, $exception->getStatusCode(), $exception->getHeaders());
 }
 public function onSilexError(GetResponseForExceptionEvent $event)
 {
     $handler = new DebugExceptionHandler($this->debug);
     $exception = $event->getException();
     if (!$exception instanceof FlattenException) {
         $exception = FlattenException::create($exception);
     }
     $response = Response::create($handler->getHtml($exception), $exception->getStatusCode(), $exception->getHeaders())->setCharset(ini_get('default_charset'));
     $event->setResponse($response);
 }
Example #11
0
 public function __toString()
 {
     try {
         return parent::__toString();
         // TODO: Change the autogenerated stub
     } catch (\Exception $exc) {
         ExceptionHelper::logException($exc);
         $eh = new ExceptionHandler(env('APP_DEBUG'));
         die($eh->getHtml($exc));
     }
 }
Example #12
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($e instanceof ErrorException) {
         // This makes use of a Symfony error handler to make pretty traces.
         $SymfonyDisplayer = new SymfonyDisplayer(config('app.debug'));
         $FlattenException = FlattenException::create($e);
         $SymfonyCss = $SymfonyDisplayer->getStylesheet($FlattenException);
         $SymfonyHtml = $SymfonyDisplayer->getContent($FlattenException);
         return response()->view('errors.500', ['error' => $e, 'error_css' => $SymfonyCss, 'error_html' => $SymfonyHtml], 500);
     } else {
         return parent::render($request, $e);
     }
 }
 /**
  * Renders the exception panel stylesheet for the given token.
  *
  * @param string $token The profiler token
  *
  * @return Response A Response instance
  *
  * @throws NotFoundHttpException
  */
 public function cssAction($token)
 {
     if (null === $this->profiler) {
         throw new NotFoundHttpException('The profiler must be enabled.');
     }
     $this->profiler->disable();
     $exception = $this->profiler->loadProfile($token)->getCollector('exception')->getException();
     $template = $this->getTemplate();
     if (!$this->templateExists($template)) {
         $handler = new ExceptionHandler($this->debug, $this->twig->getCharset());
         return new Response($handler->getStylesheet($exception), 200, array('Content-Type' => 'text/css'));
     }
     return new Response($this->twig->render('@WebProfiler/Collector/exception.css.twig'), 200, array('Content-Type' => 'text/css'));
 }
 /**
  * @param Request          $request
  * @param FlattenException $exception
  * @param string           $format
  */
 public function showAction(Request $request, FlattenException $exception, $format)
 {
     $handler = new ExceptionHandler($this->pimple['debug']);
     if ($this->pimple['debug']) {
         return $handler->createResponse($exception);
     }
     $code = $exception->getStatusCode();
     $template = $this->resolve($request, $code, $format);
     if ($template) {
         $contents = $this->pimple['twig']->render($template, array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception));
         return new Response($contents, $code);
     }
     return $handler->createResponse($exception);
 }
Example #15
0
 public function __construct($debug = true, $charset = 'UTF-8', $env = 'dev')
 {
     $this->env = $env;
     parent::__construct($debug);
     $this->debug = $debug;
     $this->fileLinkFormat = ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function createResponse($exception)
 {
     if ($exception instanceof HttpException) {
         $exception = FlattenException::create($exception, $exception->getCode());
     }
     return parent::createResponse($exception);
 }
Example #17
0
 /**
  * Enables the debug tools.
  *
  * This method registers an error handler and an exception handler.
  *
  * If the Symfony ClassLoader component is available, a special
  * class loader is also registered.
  *
  * @param int  $errorReportingLevel The level of error reporting you want
  * @param bool $displayErrors       Whether to display errors (for development) or just log them (for production)
  */
 public static function enable($errorReportingLevel = null, $displayErrors = true)
 {
     if (static::$enabled) {
         return;
     }
     static::$enabled = true;
     if ($errorReportingLevel !== null) {
         error_reporting($errorReportingLevel);
     } else {
         error_reporting(-1);
     }
     if ('cli' !== php_sapi_name()) {
         ini_set('display_errors', 0);
         ExceptionHandler::register();
     } else {
         if ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) {
             // CLI - display errors only if they're not already logged to STDERR
             ini_set('display_errors', 1);
         }
     }
     if ($displayErrors) {
         error_handler::register(new error_handler(new BufferingLogger()));
     } else {
         error_handler::register()->throwAt(0, true);
     }
     DebugClassLoader::enable();
 }
Example #18
0
 public function bootstrap()
 {
     $app = $this;
     $app['dir.base'] = __DIR__ . "/../../../../";
     $app->register(new ConfigServiceProvider());
     $app['debug'] = $app['config']['debug'];
     ErrorHandler::register();
     ExceptionHandler::register($app['debug']);
     $app->register(new HttpFragmentServiceProvider());
     $app->register(new ServiceControllerServiceProvider());
     $app->register(new ORMServiceProvider());
     $app->register(new SessionServiceProvider());
     $app->register(new SecurityServiceProvider());
     $app['security.encoder.digest'] = function ($app) {
         // uses the password-compat encryption
         return new BCryptPasswordEncoder(10);
     };
     $app->register(new ManagerRegistryServiceProvider());
     $app['security.firewalls'] = array('default' => array('pattern' => '/', 'form' => array('login_path' => '/login', 'check_path' => '/login_check'), 'logout' => array('logout_path' => '/logout', 'invalidate_session' => true), 'users' => function () use($app) {
         return new EntityUserProvider($app['manager_registry'], User::class, 'username');
     }, 'anonymous' => true));
     $app['security.access_rules'] = [['^/admin', 'ROLE_ADMIN']];
     $app->register(new TranslationServiceProvider(), array('locale_fallbacks' => array('en'), 'locale' => 'en'));
     $app->register(new ValidatorServiceProvider());
     $app->register(new FormServiceProvider());
     $app->register(new TwigServiceProvider(), ['twig.path' => __DIR__ . '/../resources/views', 'twig.form.templates' => ['bootstrap_3_layout.html.twig'], 'twig.strict_variables' => false]);
     $app->extend('twig', function (\Twig_Environment $twig) {
         $twig->addTest(new \Twig_SimpleTest('callable', function ($variable) {
             return is_callable($variable);
         }));
         $twig->addFunction(new \Twig_SimpleFunction('is_callable', function ($variable) {
             return is_callable($variable);
         }));
         $twig->addFunction(new \Twig_SimpleFunction('call_user_func', function ($callable, $params = null) {
             return call_user_func($callable, $params);
         }));
         $twig->getExtension('core')->setDateFormat('Y/m/d', '%d days');
         return $twig;
     });
     $app->extend('form.types', function ($types) use($app) {
         $types[] = new EntityType($app['manager_registry']);
         $types[] = new TemplateChoiceType($app['theme']);
         $types[] = new PageType($app['theme']);
         return $types;
     });
     $app->register(new SerializerServiceProvider());
     $app->register(new WebProfilerServiceProvider(), ['profiler.cache_dir' => './../storage/framework/cache/profiler', 'web_profiler.debug_toolbar.enable' => $app['debug'], 'profiler.mount_prefix' => '/admin/_profiler']);
     $app['finder'] = function () {
         return new Finder();
     };
     $app['filesystem'] = function () {
         return new Filesystem();
     };
     $app->register(new ConverterServiceProvider());
     $app->register(new ThemeServiceProvider());
     $app['twig.loader.filesystem']->addPath($app['dir.theme'], 'theme');
     $app->register(new CMSServiceProvider());
     $app->setRoutes();
 }
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($e instanceof HttpResponseException) {
         return $e->getResponse();
     } elseif ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     } elseif ($e instanceof AuthorizationException) {
         $e = new HttpException(403, $e->getMessage());
     } elseif ($e instanceof ValidationException && $e->getResponse()) {
         return $e->getResponse();
     }
     $fe = FlattenException::create($e);
     $handler = new SymfonyExceptionHandler(env('APP_DEBUG', false));
     $decorated = $this->decorate($handler->getContent($fe), $handler->getStylesheet($fe));
     $response = new Response($decorated, $fe->getStatusCode(), $fe->getHeaders());
     $response->exception = $e;
     return $response;
 }
 public function register(Application $app)
 {
     $debug = isset($app['config']) ? $app['config']['app.debug'] : true;
     $handler = ExceptionHandler::register($debug);
     ErrorHandler::register(E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_RECOVERABLE_ERROR);
     if ($cli = $app->runningInConsole() or $debug) {
         ini_set('display_errors', 1);
     }
     $app['exception'] = $handler;
 }
Example #21
0
 public function __construct()
 {
     parent::__construct();
     // Convert errors to exceptions
     ErrorHandler::register();
     ExceptionHandler::register();
     $this['cache.directory'] = __DIR__ . '/../../../app/cache';
     $this['vendor.directory'] = __DIR__ . '/../../../vendor';
     $this->registerControllers();
     $this->registerServiceProviders();
     $this->registerInternalServices();
 }
 public function register(Application $app)
 {
     ErrorHandler::register();
     ExceptionHandler::register($app['debug']);
     $app->error(function (\Exception $exception, $code) use($app) {
         if (!$app['debug'] || $code === 404) {
             // 404.html, or 40x.html, or 4xx.html, or error.html
             $templates = array('errors/' . $code . '.html.twig', 'errors/' . substr($code, 0, 2) . 'x.html.twig', 'errors/' . substr($code, 0, 1) . 'xx.html.twig', 'errors/' . 'default.html.twig');
             return new Response($app['twig']->resolveTemplate($templates)->render(array('code' => $code)), $code);
         }
     });
 }
 public function getContent(FlattenException $exception)
 {
     if ($exception->getStatusCode() == '500') {
         $this->logger->error($exception->getMessage(), ['code' => $exception->getCode(), 'trace' => $exception->getTrace()]);
     }
     switch (true) {
         case 404 === $exception->getStatusCode():
             if (null !== $this->translator) {
                 $title = $this->translator->trans('Sorry, the page you are looking for could not be found.');
             } else {
                 $title = 'Sorry, the page you are looking for could not be found.';
             }
             break;
         case 403 === $exception->getStatusCode():
             if (null !== $this->translator) {
                 $title = $this->translator->trans('Sorry, you do have access to the page you are looking for.');
             } else {
                 $title = 'Sorry, you do have access to the page you are looking for.';
             }
             break;
         case 500 === $exception->getStatusCode():
             if (null !== $this->translator) {
                 $title = $this->translator->trans('Whoops, looks like something went wrong.');
             } else {
                 $title = 'Whoops, looks like something went wrong.';
             }
             break;
         case 503 === $exception->getStatusCode():
             if (null !== $this->translator) {
                 $title = $this->translator->trans('Sorry, site is currently undergoing maintenance, come back soon.');
             } else {
                 $title = 'Sorry, site is currently undergoing maintenance, come back soon.';
             }
             break;
         case isset(Response::$statusTexts[$exception->getStatusCode()]):
             $title = $exception->getStatusCode() . ' : ' . Response::$statusTexts[$exception->getStatusCode()];
             break;
         default:
             if (null !== $this->translator) {
                 $title = $this->translator->trans('Whoops, looks like something went wrong.');
             } else {
                 $title = 'Whoops, looks like something went wrong.';
             }
     }
     $content = parent::getContent($exception);
     $start = strpos($content, '</h1>');
     $content = '<div id="sf-resetcontent" class="sf-reset">' . '<h1><span>' . $title . '</span></h1>' . substr($content, $start + 5);
     return $content;
 }
Example #24
0
 /**
  * Enables the debug tools.
  *
  * This method registers an error handler and an exception handler.
  *
  * If the Symfony ClassLoader component is available, a special
  * class loader is also registered.
  *
  * @param integer $errorReportingLevel The level of error reporting you want
  * @param Boolean $displayErrors       Whether to display errors (for development) or just log them (for production)
  */
 public static function enable($errorReportingLevel = null, $displayErrors = true)
 {
     if (static::$enabled) {
         return;
     }
     static::$enabled = true;
     error_reporting(-1);
     ErrorHandler::register($errorReportingLevel, $displayErrors);
     if ('cli' !== php_sapi_name()) {
         ExceptionHandler::register();
         // CLI - display errors only if they're not already logged to STDERR
     } elseif ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) {
         ini_set('display_errors', 1);
     }
     DebugClassLoader::enable();
 }
Example #25
0
 /**
  * Enables the debug tools.
  *
  * This method registers an error handler and an exception handler.
  *
  * If the Symfony ClassLoader component is available, a special
  * class loader is also registered.
  *
  * @param integer $errorReportingLevel The level of error reporting you want
  */
 public static function enable($errorReportingLevel = null)
 {
     if (static::$enabled) {
         return;
     }
     static::$enabled = true;
     error_reporting(-1);
     ErrorHandler::register($errorReportingLevel);
     if ('cli' !== php_sapi_name()) {
         ExceptionHandler::register();
     } elseif (!ini_get('log_errors') || ini_get('error_log')) {
         ini_set('display_errors', 1);
     }
     if (class_exists('Symfony\\Component\\ClassLoader\\DebugClassLoader')) {
         DebugClassLoader::enable();
     }
 }
 public function onKernelException(GetResponseForExceptionEvent $e)
 {
     $ex = $e->getException();
     $response = new Response();
     if ($ex instanceof NotFoundHttpException) {
         $response->setContent($this->view->render('error/404'));
         $e->setResponse($response);
         return;
     }
     if ($this->debugMode) {
         \Symfony\Component\Debug\ExceptionHandler::register();
         throw $ex;
     }
     $response->setContent($this->view->render('error/exception'));
     $e->setResponse($response);
     $this->logger->handleException($ex);
 }
 /**
  * Sets default exception handler.
  *
  * If shop is in productive mode stick to default OXID exception handler
  * Else register Symfony Debug component's Exception and Error handlers
  *
  * Non-productive eShop mode is intended for eShop installation, configuration, template customization and module debugging phase.
  * As soon as productive mode is turned ON, the cache handling and the error reporting behavior is optimized for the live shop.
  */
 protected function _setDefaultExceptionHandler()
 {
     /**
      * @todo: consider also getEnvironment() function to detect environment
      */
     if (oxRegistry::getConfig()->isProductiveMode()) {
         parent::_setDefaultExceptionHandler();
         return;
     }
     /**
      * Debug::enable() also registers a DebugClassLoader which throw an error because oxid does not care about case when referring to objects
      * symfony is key sensitive:  oxarticlelist != oxArticleList
      */
     //Debug\Debug::enable();
     ini_set('display_errors', 0);
     Debug\ExceptionHandler::register();
     Debug\ErrorHandler::register()->throwAt(0, true);
 }
 /**
  * Enables the debug tools.
  *
  * This method registers an error handler and an exception handler.
  *
  * If the Symfony ClassLoader component is available, a special
  * class loader is also registered.
  *
  * @param int  $errorReportingLevel The level of error reporting you want
  * @param bool $displayErrors       Whether to display errors (for development) or just log them (for production)
  */
 public static function enable($errorReportingLevel = null, $displayErrors = true)
 {
     if (static::$enabled) {
         return;
     }
     static::$enabled = true;
     error_reporting(-1);
     ErrorHandler::register($errorReportingLevel, $displayErrors);
     if ('cli' !== PHP_SAPI) {
         ExceptionHandler::register();
         // CLI - display errors only if they're not already logged to STDERR
     } elseif ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) {
         ini_set('display_errors', 1);
     }
     if (class_exists('Symfony\\Component\\ClassLoader\\DebugClassLoader')) {
         DebugClassLoader::enable();
     }
 }
Example #29
0
 /**
  *  Init config
  * 
  * @param Application $app
  */
 private function _iniConfig(Application $app)
 {
     // Setting the sign of the console
     $app['is_console'] = TRUE;
     // Load configurations
     $app->register(new Providers\YamlConfigServiceProvider(array('%base_path%' => BASEPATH, '%log_path%' => BASEPATH . '/data/logs', '%cache_path%' => BASEPATH . '/data/cache')), array('config.dir' => BASEPATH . '/app/Resources/Config', 'config.files' => array('console.yml')));
     //Set debug option
     $app['debug'] = $app['config']['parameters']['debug'];
     //Set basepath option
     $app['basepath'] = $this->app['config']['base_path'];
     //Set Timezone
     if (isset($app['config']['parameters']['timezone'])) {
         date_default_timezone_set($app['config']['parameters']['timezone']);
     }
     // Registering the ErrorHandler
     // It converts all errors to exceptions, and exceptions are then caught by Silex
     ErrorHandler::register();
     ExceptionHandler::register($app['debug']);
 }
Example #30
0
 /**
  * Set the handlers.
  *
  * @param bool $debug
  */
 public static function register($debug = true)
 {
     $errorLevels = error_reporting();
     if ($debug) {
         $errorLevels |= E_RECOVERABLE_ERROR | E_USER_ERROR | E_DEPRECATED | E_USER_DEPRECATED;
         Debug\DebugClassLoader::enable();
     }
     if (PHP_SAPI !== 'cli') {
         Debug\ErrorHandler::register()->throwAt($errorLevels, true);
         Debug\ExceptionHandler::register($debug);
     } else {
         $consoleHandler = function (\Exception $e) {
             $app = new Application('Bolt CLI', Version::VERSION);
             $output = new ConsoleOutput(OutputInterface::VERBOSITY_DEBUG);
             $app->renderException($e, $output);
             ob_clean();
         };
         Debug\ExceptionHandler::register($debug)->setHandler($consoleHandler);
     }
 }