Beispiel #1
0
 /**
  * @param Exception $exception
  *
  * @return void
  */
 private function log(Exception $exception)
 {
     $class = get_class($exception);
     $code = 0;
     $type = $class;
     if ($exception instanceof ErrorException) {
         $code = $exception->getSeverity();
         $type = ErrorHandler::getErrorType($code);
     }
     // Unpack exceptions
     $exceptions = [$exception];
     $e = $exception;
     while ($e = $e->getPrevious()) {
         $exceptions[] = $e;
     }
     $context = ['errorCode' => $code, 'errorType' => $type, 'errorClass' => $class, 'errorStacktrace' => $this->formatStacktraceForExceptions($exceptions)];
     $this->logger->error($exception->getMessage(), $context);
 }
 /**
  * @param Exception|Throwable $throwable
  * @param string $level
  *
  * @return void
  */
 private function logError($throwable, $level)
 {
     $class = get_class($throwable);
     $code = 0;
     $type = $class;
     if ($throwable instanceof ErrorException) {
         $code = $throwable->getSeverity();
         $type = ErrorHandler::getErrorType($code);
     }
     // Unpack throwables
     $throwables = $this->unpackThrowables($throwable);
     $context = ['errorCode' => $code, 'errorType' => $type, 'errorClass' => $class, 'errorStacktrace' => $this->formatStacktraceForExceptions($throwables)];
     $this->log($level, $throwable->getMessage(), $context);
 }
 /**
  * @param ResponseInterface $response
  * @param Throwable|Exception $throwable
  *
  * @return ResponseInterface
  */
 private function withError(ResponseInterface $response, $throwable)
 {
     if ($throwable instanceof ErrorException) {
         $severity = ErrorHandler::getErrorType($throwable->getSeverity());
     } else {
         $severity = 'Error';
     }
     $contents = ['message' => 'Application Error', 'status' => 500, 'severity' => $severity, 'throwable' => $throwable];
     if ($this->displayErrorDetails) {
         $throwables = $this->unpackThrowables($throwable);
         $contents['details'] = $this->formatStacktraceForExceptions($throwables);
         $contents['message'] = $throwable->getMessage();
     }
     return $this->withHTML($response, $contents)->withStatus(500);
 }
 public function testErrorSeverityDescription()
 {
     $this->assertSame('Deprecated', ErrorHandler::getErrorDescription(\E_DEPRECATED));
     $this->assertSame('User Deprecated', ErrorHandler::getErrorDescription(\E_USER_DEPRECATED));
     $this->assertSame('Notice', ErrorHandler::getErrorDescription(\E_NOTICE));
     $this->assertSame('User Notice', ErrorHandler::getErrorDescription(\E_USER_NOTICE));
     $this->assertSame('Runtime Notice', ErrorHandler::getErrorDescription(\E_STRICT));
     $this->assertSame('Warning', ErrorHandler::getErrorDescription(\E_WARNING));
     $this->assertSame('User Warning', ErrorHandler::getErrorDescription(\E_USER_WARNING));
     $this->assertSame('Compile Warning', ErrorHandler::getErrorDescription(\E_COMPILE_WARNING));
     $this->assertSame('Core Warning', ErrorHandler::getErrorDescription(\E_CORE_WARNING));
     $this->assertSame('User Error', ErrorHandler::getErrorDescription(\E_USER_ERROR));
     $this->assertSame('Catchable Fatal Error', ErrorHandler::getErrorDescription(\E_RECOVERABLE_ERROR));
     $this->assertSame('Compile Error', ErrorHandler::getErrorDescription(\E_COMPILE_ERROR));
     $this->assertSame('Parse Error', ErrorHandler::getErrorDescription(\E_PARSE));
     $this->assertSame('Error', ErrorHandler::getErrorDescription(\E_ERROR));
     $this->assertSame('Core Error', ErrorHandler::getErrorDescription(\E_CORE_ERROR));
     $this->assertSame('Exception', ErrorHandler::getErrorDescription('derp'));
 }