Set up a loop error handler

This commit is contained in:
Daniil Gentili 2024-06-30 16:12:30 +02:00
parent 781766f849
commit f484ee67a7

View File

@ -1,5 +1,8 @@
<?php
use Amp\Future\UnhandledFutureError;
use Amp\SignalException;
use danog\MadelineProto\SecurityException;
use Revolt\EventLoop;
use TelegramApiServer\Logger;
use TelegramApiServer\Migrations\EnvUpgrade;
@ -113,3 +116,16 @@ if (!function_exists('emergency')) {
Logger::getInstance()->emergency($message, $context);
}
}
EventLoop::setErrorHandler(function (\Throwable $e) {
if ($e instanceof UnhandledFutureError) {
$e = $e->getPrevious();
}
if ($e instanceof SecurityException || $e instanceof SignalException) {
throw $e;
}
if (str_starts_with($e->getMessage(), 'Could not connect to DC ')) {
throw $e;
}
emergency((string) $e);
});