[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 committed by Diogo Peralta Cordeiro
parent 71b1ee7796
commit 47daf6169a
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0

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