Skip to content

Commit c0d7504

Browse files
committed
consulta tipo de cambio
1 parent ead4073 commit c0d7504

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Application/Api/TipoCambioController.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function getTipoCambio(Request $request, Response $response, array $args)
5656

5757
// 5. Consultar API externa de tipo de cambio
5858
$remoteResponse = $this->remoteQuery($date, $apiTokenRecord->token);
59-
59+
6060
// 7. Incrementar contador del token usado
6161
$apiTokenRecord->incrementCounter();
6262

@@ -163,6 +163,16 @@ private function remoteQuery(string $date, string $apiToken): array
163163
'status_code' => 400
164164
];
165165
}
166+
if ($e->hasResponse() && $e->getResponse()->getStatusCode() === 404) {
167+
$body = (string) $e->getResponse()->getBody();
168+
$errorData = json_decode($body, true);
169+
170+
return [
171+
'error' => 'Fecha no válida o sin datos',
172+
'message' => $errorData['error'] ?? 'Invalid request',
173+
'status_code' => 404
174+
];
175+
}
166176

167177
return [
168178
'error' => 'Error al consultar la API externa de tipo de cambio: ' . $e->getMessage(),

0 commit comments

Comments
 (0)