Logging
This commit is contained in:
@ -20,4 +20,5 @@ register_shutdown_function(function() {
|
|||||||
if ($error !== null and in_array($error['type'], $fatal_errors, true)) {
|
if ($error !== null and in_array($error['type'], $fatal_errors, true)) {
|
||||||
error_log(json_encode($error).PHP_EOL,3, '/logs/fatal.log');
|
error_log(json_encode($error).PHP_EOL,3, '/logs/fatal.log');
|
||||||
}
|
}
|
||||||
|
error_clear_last();
|
||||||
});
|
});
|
||||||
|
@ -47,15 +47,20 @@ class Toku extends Controller
|
|||||||
ResponseFactoryInterface $responseFactory,
|
ResponseFactoryInterface $responseFactory,
|
||||||
Service\Venta\MediosPago\Toku $tokuService): ResponseInterface
|
Service\Venta\MediosPago\Toku $tokuService): ResponseInterface
|
||||||
{
|
{
|
||||||
$body = $request->getBody();
|
$body = $request->getBody()->getContents();
|
||||||
$input = json_decode($body->getContents(), true);
|
$input = json_decode($body, true);
|
||||||
try {
|
try {
|
||||||
if ($tokuService->successEvent($input)) {
|
if ($tokuService->successEvent($input)) {
|
||||||
return $responseFactory->createResponse(200);
|
return $responseFactory->createResponse(200);
|
||||||
}
|
}
|
||||||
|
$this->logger->warning("Could not update payment", ['input' => $input]);
|
||||||
return $responseFactory->createResponse(409, 'Payment could not be updated');
|
return $responseFactory->createResponse(409, 'Payment could not be updated');
|
||||||
} catch (InvalidResult $exception) {
|
} catch (InvalidResult $exception) {
|
||||||
$this->logger->warning($exception);
|
$this->logger->warning($exception, [
|
||||||
|
'uri' => $request->getUri()->getPath(),
|
||||||
|
'body' => $body,
|
||||||
|
'input' => $input
|
||||||
|
]);
|
||||||
if (str_contains($exception->getMessage(), 'Customer')) {
|
if (str_contains($exception->getMessage(), 'Customer')) {
|
||||||
$message = 'Customer not found';
|
$message = 'Customer not found';
|
||||||
} elseif (str_contains($exception->getMessage(), 'Invoice')) {
|
} elseif (str_contains($exception->getMessage(), 'Invoice')) {
|
||||||
|
@ -30,11 +30,23 @@ abstract class AbstractEndPoint extends LoggerEnabled implements EndPoint
|
|||||||
|
|
||||||
if (in_array($status, $invalidStatus)) {
|
if (in_array($status, $invalidStatus)) {
|
||||||
$contents = $response->getBody()->getContents();
|
$contents = $response->getBody()->getContents();
|
||||||
|
$this->logger->warning('Invalid Status', [
|
||||||
|
'uri' => $request_uri,
|
||||||
|
'code' => $status,
|
||||||
|
'reason' => $reason,
|
||||||
|
'contents' => $contents
|
||||||
|
]);
|
||||||
$exception = new HttpException("{$reason}\n{$contents}", $status);
|
$exception = new HttpException("{$reason}\n{$contents}", $status);
|
||||||
throw new EmptyResponse($request_uri, $exception);
|
throw new EmptyResponse($request_uri, $exception);
|
||||||
}
|
}
|
||||||
if (!in_array($status, $validStatus)) {
|
if (!in_array($status, $validStatus)) {
|
||||||
$contents = $response->getBody()->getContents();
|
$contents = $response->getBody()->getContents();
|
||||||
|
$this->logger->warning('Not Valid Status', [
|
||||||
|
'uri' => $request_uri,
|
||||||
|
'code' => $status,
|
||||||
|
'reason' => $reason,
|
||||||
|
'contents' => $contents
|
||||||
|
]);
|
||||||
$exception = new HttpException("{$reason}\n{$contents}", $status);
|
$exception = new HttpException("{$reason}\n{$contents}", $status);
|
||||||
throw new EmptyResponse($request_uri, $exception);
|
throw new EmptyResponse($request_uri, $exception);
|
||||||
}
|
}
|
||||||
@ -80,6 +92,13 @@ abstract class AbstractEndPoint extends LoggerEnabled implements EndPoint
|
|||||||
|
|
||||||
$contents = $response->getBody()->getContents();
|
$contents = $response->getBody()->getContents();
|
||||||
if (trim($contents) === '') {
|
if (trim($contents) === '') {
|
||||||
|
$this->logger->warning("Empty contents", [
|
||||||
|
'uri' => $request_uri,
|
||||||
|
'data' => $data,
|
||||||
|
'code' => $response->getStatusCode(),
|
||||||
|
'reason' => $response->getReasonPhrase(),
|
||||||
|
'contents' => $contents
|
||||||
|
]);
|
||||||
throw new EmptyResponse($request_uri);
|
throw new EmptyResponse($request_uri);
|
||||||
}
|
}
|
||||||
$json = json_decode($contents, true);
|
$json = json_decode($contents, true);
|
||||||
|
Reference in New Issue
Block a user