From 38a331220fda8c21017ba399b574c5ac83aaaee9 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sat, 7 Aug 2021 18:21:20 +0000 Subject: [PATCH] [CORE][Log] Add Log::unexpected_exception utility which logs and throws a ServerException --- src/Core/Log.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Core/Log.php b/src/Core/Log.php index dafdf7df89..1b6a13b3de 100644 --- a/src/Core/Log.php +++ b/src/Core/Log.php @@ -31,6 +31,7 @@ namespace App\Core; +use App\Util\Exception\ServerException; use Psr\Log\LoggerInterface; abstract class Log @@ -42,6 +43,13 @@ abstract class Log self::$logger = $l; } + public static function unexpected_exception(\Exception $e) + { + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); + self::critical('Unexpected exception of class: "' . get_class($e) . '" was thrown in ' . get_called_class() . '::' . $backtrace[1]['function']); + throw new ServerException('Unexpected exception', 500, $e); + } + /** * Simple static wrappers around Monolog's functions */