Better logging

This commit is contained in:
Juan Pablo Vial
2025-07-03 17:17:55 -04:00
parent 239376fadc
commit 18e79b76d6

View File

@ -137,7 +137,11 @@ class Subscription extends AbstractEndPoint
$statement = $this->ventaService->getRepository()->getConnection()->execute($query, $values); $statement = $this->ventaService->getRepository()->getConnection()->execute($query, $values);
$results = $statement->fetchAll(PDO::FETCH_ASSOC); $results = $statement->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $exception) { } catch (PDOException $exception) {
$this->logger->error($exception); $this->logger->error($exception->getMessage(), [
'query' => $query,
'values' => $values,
'ids' => $idsData,
'exception' => $exception]);
throw new EmptyResult($query, $exception); throw new EmptyResult($query, $exception);
} }
@ -162,11 +166,34 @@ class Subscription extends AbstractEndPoint
]; ];
try { try {
if (!$this->edit($tokuId, $data, array_key_exists($idx, $keys) ? $keys[$idx] : null)) { if (!$this->edit($tokuId, $data, array_key_exists($idx, $keys) ? $keys[$idx] : null)) {
$this->logger->error("Error while updating Toku {$tokuId}"); $this->logger->error('Error while updating Toku', [
'toku_id' => $tokuId,
'old_pid' => $oldPids[$idx],
'product_id' => $newPids[$idx],
'account_key' => array_key_exists($idx, $keys) ? $keys[$idx] : null]);
$output[] = [
'toku_id' => $tokuId,
'old_pid' => $oldPids[$idx],
'product_id' => $newPids[$idx],
'account_key' => array_key_exists($idx, $keys) ? $keys[$idx] : null,
'error' => 'Error while updating Toku'
];
continue; continue;
} }
} catch (EmptyResponse $exception) { } catch (EmptyResponse $exception) {
$this->logger->error($exception); $this->logger->error($exception->getMessage(), [
'toku_id' => $tokuId,
'old_pid' => $oldPids[$idx],
'product_id' => $newPids[$idx],
'account_key' => array_key_exists($idx, $keys) ? $keys[$idx] : null,
'exception' => $exception]);
$output[] = [
'toku_id' => $tokuId,
'old_pid' => $oldPids[$idx],
'product_id' => $newPids[$idx],
'account_key' => array_key_exists($idx, $keys) ? $keys[$idx] : null,
'error' => $exception->getMessage()
];
continue; continue;
} }
$output[] = [ $output[] = [
@ -262,7 +289,10 @@ class Subscription extends AbstractEndPoint
$statement = $this->ventaService->getRepository()->getConnection()->execute($query, $values); $statement = $this->ventaService->getRepository()->getConnection()->execute($query, $values);
$results = $statement->fetchAll(PDO::FETCH_ASSOC); $results = $statement->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $exception) { } catch (PDOException $exception) {
$this->logger->error($exception); $this->logger->error($exception->getMessage(), [
'query' => $query,
'values' => $values,
'exception' => $exception]);
throw new EmptyResult($query, $exception); throw new EmptyResult($query, $exception);
} }
$keys = array_column($results, 'account_key'); $keys = array_column($results, 'account_key');