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 public function __invoke(LogRecord $record): LogRecord
{ {
$context = $record->context; $context = $record->context;
foreach ($context as $key => $value) { $changed = false;
if (is_a($value, Throwable::class)) { array_walk_recursive($context, function (&$item) use (&$changed) {
$exception = $value; if (is_a($item, Throwable::class)) {
$output = $this->processException($exception); $item = $this->processException($item);
$context[$key] = $output; $changed = true;
$new_record = new LogRecord(
$record->datetime,
$record->channel,
$record->level,
$record->message,
$context,
$record->extra
);
$record = $new_record;
} }
});
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)) { if (is_a($record->message, Throwable::class)) {
$exception = $record->message; $exception = $record->message;

View File

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

View File

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