FIX:Unavailable value for tipocambio crashed the loading of values
This commit is contained in:
@ -5,6 +5,7 @@ use Carbon\Carbon;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\ConnectException;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Exception\ServerException;
|
||||
use ProVM\Common\Factory\Model as Factory;
|
||||
use Contabilidad\Moneda;
|
||||
use Contabilidad\TipoCambio;
|
||||
@ -35,7 +36,7 @@ class TiposCambios {
|
||||
'desde' => $moneda_codigo
|
||||
];
|
||||
$headers = [
|
||||
'Authorization' => 'Bearer ' . $this->key
|
||||
'Authorization' => "Bearer {$this->key}"
|
||||
];
|
||||
$url = implode('/', [
|
||||
$this->base_url,
|
||||
@ -44,14 +45,19 @@ class TiposCambios {
|
||||
]);
|
||||
try {
|
||||
$response = $this->client->request('POST', $url, ['json' => $data, 'headers' => $headers]);
|
||||
} catch (ConnectException | RequestException $e) {
|
||||
} catch (ConnectException | RequestException | ServerException $e) {
|
||||
error_log($e);
|
||||
return null;
|
||||
}
|
||||
if ($response->getStatusCode() !== 200) {
|
||||
error_log('Could not connect to python API.');
|
||||
return null;
|
||||
}
|
||||
$result = json_decode($response->getBody());
|
||||
if (isset($result->message) and $result->message === 'Not Authorized') {
|
||||
error_log('Not authorized for connecting to python API.');
|
||||
return null;
|
||||
}
|
||||
return $result->serie[0]->valor;
|
||||
}
|
||||
public function get(string $fecha, int $moneda_id) {
|
||||
@ -62,7 +68,7 @@ class TiposCambios {
|
||||
}
|
||||
// If a value exists in the database
|
||||
$cambio = $moneda->cambio($fecha);
|
||||
if ($cambio) {
|
||||
if ($cambio !== null) {
|
||||
if ($cambio->desde()->id != $moneda->id) {
|
||||
return 1 / $cambio->valor;
|
||||
}
|
||||
|
Reference in New Issue
Block a user