[CORE][Log] Add Log::unexpected_exception utility which logs and throws a ServerException

This commit is contained in:
Hugo Sales 2021-08-07 18:21:20 +00:00
parent 085e880631
commit 38a331220f
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -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
*/