forked from EvergreenCrypto/docker-finance
container: finance: fetch: prices: improve handling of non-200 responses
This commit is contained in:
@@ -361,16 +361,17 @@ namespace dfi\prices\internal
|
|||||||
$code = $e->getCode();
|
$code = $e->getCode();
|
||||||
$message = $e->getMessage();
|
$message = $e->getMessage();
|
||||||
|
|
||||||
$print = "server sent error '{$message}' with code '{$code}' for '{$asset['id']}'"
|
$print = "server sent error '{$message}' with code '{$code}' for '{$asset['id']}'";
|
||||||
. " - retrying in '{$timer}' seconds";
|
|
||||||
|
|
||||||
switch ($code) {
|
switch ($code) {
|
||||||
// CoinGecko's unrecoverable error (paid plan needed)
|
case 400:
|
||||||
case 10012:
|
utils\CLI::throw_fatal($print);
|
||||||
|
break;
|
||||||
|
case 10012: // CoinGecko's unrecoverable error (paid plan needed)
|
||||||
utils\CLI::throw_fatal($print);
|
utils\CLI::throw_fatal($print);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
utils\CLI::print_warning($print);
|
utils\CLI::print_warning($print . " - retrying in '{$timer}' seconds");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
// docker-finance | modern accounting for the power-user
|
// docker-finance | modern accounting for the power-user
|
||||||
//
|
//
|
||||||
// Copyright (C) 2021-2025 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
// Copyright (C) 2021-2026 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// This program is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
@@ -182,6 +182,14 @@ namespace dfi\prices\internal\prices\crypto
|
|||||||
}
|
}
|
||||||
|
|
||||||
$response = $this->request_impl($url, $header);
|
$response = $this->request_impl($url, $header);
|
||||||
|
if (array_key_exists('statusCode', $response)) {
|
||||||
|
switch ($response['statusCode']) {
|
||||||
|
case 200:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new \Exception($response['message'], $response['statusCode']);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (array_key_exists('error', $response)) {
|
if (array_key_exists('error', $response)) {
|
||||||
throw new \Exception($response['error']);
|
throw new \Exception($response['error']);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user