/** * @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 testErrorSeverityType() { $this->assertSame('E_DEPRECATED', ErrorHandler::getErrorType(\E_DEPRECATED)); $this->assertSame('E_USER_DEPRECATED', ErrorHandler::getErrorType(\E_USER_DEPRECATED)); $this->assertSame('E_NOTICE', ErrorHandler::getErrorType(\E_NOTICE)); $this->assertSame('E_USER_NOTICE', ErrorHandler::getErrorType(\E_USER_NOTICE)); $this->assertSame('E_STRICT', ErrorHandler::getErrorType(\E_STRICT)); $this->assertSame('E_WARNING', ErrorHandler::getErrorType(\E_WARNING)); $this->assertSame('E_USER_WARNING', ErrorHandler::getErrorType(\E_USER_WARNING)); $this->assertSame('E_COMPILE_WARNING', ErrorHandler::getErrorType(\E_COMPILE_WARNING)); $this->assertSame('E_CORE_WARNING', ErrorHandler::getErrorType(\E_CORE_WARNING)); $this->assertSame('E_USER_ERROR', ErrorHandler::getErrorType(\E_USER_ERROR)); $this->assertSame('E_RECOVERABLE_ERROR', ErrorHandler::getErrorType(\E_RECOVERABLE_ERROR)); $this->assertSame('E_COMPILE_ERROR', ErrorHandler::getErrorType(\E_COMPILE_ERROR)); $this->assertSame('E_PARSE', ErrorHandler::getErrorType(\E_PARSE)); $this->assertSame('E_ERROR', ErrorHandler::getErrorType(\E_ERROR)); $this->assertSame('E_CORE_ERROR', ErrorHandler::getErrorType(\E_CORE_ERROR)); $this->assertSame('UNKNOWN', ErrorHandler::getErrorType('derp')); }