Abstract error logging and ignore some errors when deleting stations.
This commit is contained in:
parent
edd21605c0
commit
f3e411beb9
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
namespace App\Exception\Supervisor;
|
||||
|
||||
class BadName extends \App\Exception\Supervisor
|
||||
{
|
||||
}
|
|
@ -64,26 +64,8 @@ class ErrorHandler
|
|||
}
|
||||
|
||||
// Don't log errors that are internal to the application.
|
||||
$e_level = ($e instanceof \Azura\Exception)
|
||||
? $e->getLoggerLevel()
|
||||
: Logger::ERROR;
|
||||
|
||||
$show_detailed = !APP_IN_PRODUCTION && $e_level >= Logger::ERROR;
|
||||
|
||||
$e_extra = [];
|
||||
if ($e instanceof \Azura\Exception) {
|
||||
$e_extra['context'] = $e->getLoggingContext();
|
||||
$e_extra = array_merge($e_extra, $e->getExtraData());
|
||||
}
|
||||
if ($show_detailed) {
|
||||
$e_extra['trace'] = array_slice($e->getTrace(), 0, 5);
|
||||
}
|
||||
|
||||
$this->logger->addRecord($e_level, $e->getMessage(), [
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
'code' => $e->getCode(),
|
||||
] + $e_extra);
|
||||
$e_extra = self::logException($this->logger, $e);
|
||||
$show_detailed = isset($e_extra['trace']);
|
||||
|
||||
// Special handling for cURL (i.e. Liquidsoap) requests.
|
||||
$ua = $req->getHeaderLine('User-Agent');
|
||||
|
@ -187,4 +169,39 @@ class ErrorHandler
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Logger $logger
|
||||
* @param \Throwable $e
|
||||
* @param bool|null $include_trace
|
||||
* @return array The logging context.
|
||||
*/
|
||||
public static function logException(Logger $logger, \Throwable $e, $include_trace = null): array
|
||||
{
|
||||
$e_level = ($e instanceof \Azura\Exception)
|
||||
? $e->getLoggerLevel()
|
||||
: Logger::ERROR;
|
||||
|
||||
if (null === $include_trace) {
|
||||
$include_trace = !APP_IN_PRODUCTION && $e_level >= Logger::ERROR;
|
||||
}
|
||||
|
||||
$context = [
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
'code' => $e->getCode(),
|
||||
];
|
||||
|
||||
if ($e instanceof \Azura\Exception) {
|
||||
$context['context'] = $e->getLoggingContext();
|
||||
$context = array_merge($context, $e->getExtraData());
|
||||
}
|
||||
|
||||
if ($include_trace) {
|
||||
$context['trace'] = array_slice($e->getTrace(), 0, 5);
|
||||
}
|
||||
|
||||
$logger->addRecord($e_level, $e->getMessage(), $context);
|
||||
return $context;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,7 +187,16 @@ abstract class AbstractAdapter
|
|||
$class_parts = explode('\\', static::class);
|
||||
$class_name = array_pop($class_parts);
|
||||
|
||||
if (false !== stripos($e->getMessage(), 'ALREADY_STARTED')) {
|
||||
if (false !== stripos($e->getMessage(), 'BAD_NAME')) {
|
||||
$e_headline = __('%s is not recognized as a service.', $class_name);
|
||||
$e_body = __('It may not be registered with Supervisor yet. Restarting broadcasting may help.');
|
||||
|
||||
$app_e = new \App\Exception\Supervisor\BadName(
|
||||
$e_headline.'; '.$e_body,
|
||||
$e->getCode(),
|
||||
$e
|
||||
);
|
||||
} else if (false !== stripos($e->getMessage(), 'ALREADY_STARTED')) {
|
||||
$e_headline = __('%s cannot start', $class_name);
|
||||
$e_body = __('It is already running.');
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
namespace App\Radio;
|
||||
|
||||
use App\Http\ErrorHandler;
|
||||
use App\Radio\Frontend\AbstractFrontend;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use App\Entity\Station;
|
||||
use fXmlRpc\Exception\FaultException;
|
||||
use Monolog\Logger;
|
||||
use Supervisor\Supervisor;
|
||||
|
||||
|
@ -189,8 +191,13 @@ class Configuration
|
|||
$affected_groups = $this->_reloadSupervisor();
|
||||
|
||||
if (!in_array($station_group, $affected_groups, true)) {
|
||||
$this->supervisor->stopProcessGroup($station_group, true);
|
||||
$this->supervisor->removeProcessGroup($station_group);
|
||||
// Try forcing the group to stop, but don't hard-fail if it doesn't.
|
||||
try {
|
||||
$this->supervisor->stopProcessGroup($station_group, true);
|
||||
$this->supervisor->removeProcessGroup($station_group);
|
||||
} catch(FaultException $e) {
|
||||
ErrorHandler::logException($this->logger, $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
namespace App\Sync\Task;
|
||||
|
||||
use App\Http\ErrorHandler;
|
||||
use App\MessageQueue;
|
||||
use Azura\Cache;
|
||||
use App\Event\Radio\GenerateRawNowPlaying;
|
||||
|
@ -290,11 +291,7 @@ class NowPlaying extends AbstractTask implements EventSubscriberInterface
|
|||
$this->event_dispatcher->dispatch(GenerateRawNowPlaying::NAME, $event);
|
||||
$np_raw = $event->getRawResponse();
|
||||
} catch(\Exception $e) {
|
||||
$this->logger->error($e->getMessage(), [
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
'code' => $e->getCode(),
|
||||
]);
|
||||
ErrorHandler::logException($this->logger, $e);
|
||||
$np_raw = AdapterAbstract::NOWPLAYING_EMPTY;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue