Use exception processor

This commit is contained in:
Juan Pablo Vial
2025-10-03 11:56:05 -03:00
parent 032d00fbb6
commit fe8bbb5767
3 changed files with 18 additions and 22 deletions

View File

@ -10,21 +10,23 @@ class Exception implements ProcessorInterface
public function __invoke(LogRecord $record): LogRecord
{
$context = $record->context;
foreach ($context as $key => $value) {
if (is_a($value, Throwable::class)) {
$exception = $value;
$output = $this->processException($exception);
$context[$key] = $output;
$new_record = new LogRecord(
$record->datetime,
$record->channel,
$record->level,
$record->message,
$context,
$record->extra
);
$record = $new_record;
$changed = false;
array_walk_recursive($context, function (&$item) use (&$changed) {
if (is_a($item, Throwable::class)) {
$item = $this->processException($item);
$changed = true;
}
});
if ($changed) {
$new_record = new LogRecord(
$record->datetime,
$record->channel,
$record->level,
$record->message,
$context,
$record->extra
);
$record = $new_record;
}
if (is_a($record->message, Throwable::class)) {
$exception = $record->message;

View File

@ -79,13 +79,7 @@ class Queue extends Ideal\Service
try {
$this->jobService->update($job);
} catch (Update $exception) {
$this->logger->error($exception->getMessage(), ['job' => $job, 'exception' => [
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => $exception->getTraceAsString(),
]]);
$this->logger->error($exception->getMessage(), ['job' => $job, 'exception' => $exception]);
}
return false;
}

View File

@ -174,7 +174,7 @@ class Reservation extends Ideal\Service\API
$this->reservationRepository->getConnection()->getPDO()->commit();
}
} catch (PDOException $exception) {
$this->logger->warning($exception->getMessage(), ['exception' => $exception->getTraceAsString()]);
$this->logger->warning($exception->getMessage(), ['exception' => $exception]);
if ($this->reservationRepository->getConnection()->getPDO()->inTransaction()) {
$this->reservationRepository->getConnection()->getPDO()->rollBack();
}