From f222a5e6548b4d198e4d266fefee2317cf7b7104 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Tue, 30 Jul 2024 22:42:15 -0700 Subject: [PATCH 1/2] php: fetch: prices: crypto: throw errors with nested status --- .../lib/internal/fetch/prices/internal/prices/crypto.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/container/src/finance/lib/internal/fetch/prices/internal/prices/crypto.php b/container/src/finance/lib/internal/fetch/prices/internal/prices/crypto.php index fa8784b..19a12cb 100644 --- a/container/src/finance/lib/internal/fetch/prices/internal/prices/crypto.php +++ b/container/src/finance/lib/internal/fetch/prices/internal/prices/crypto.php @@ -58,6 +58,10 @@ namespace docker_finance\prices\internal\prices\crypto $url = "https://{$domain}/api/v3/coins/{$asset['id']}/market_chart?vs_currency={$vs_currency}&days={$timestamp}"; $response = $this->request_impl($url, $header); + if (array_key_exists('error', $response)) { + $status = $response['error']['status']; + throw new \Exception($status['error_message'], $status['error_code']); + } if (array_key_exists('status', $response)) { $status = $response['status']; throw new \Exception($status['error_message'], $status['error_code']); From d7b25e0dae00fa8c5c7609842951d711857dc0f0 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Tue, 30 Jul 2024 22:42:51 -0700 Subject: [PATCH 2/2] php: fetch: prices: base: catch unrecoverable CoinGecko error Thrown when 'all' years are requested without paid-plan API key. --- .../lib/internal/fetch/prices/internal/base.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/container/src/finance/lib/internal/fetch/prices/internal/base.php b/container/src/finance/lib/internal/fetch/prices/internal/base.php index adc4dbb..84267a8 100644 --- a/container/src/finance/lib/internal/fetch/prices/internal/base.php +++ b/container/src/finance/lib/internal/fetch/prices/internal/base.php @@ -354,10 +354,18 @@ namespace docker_finance\prices\internal $code = $e->getCode(); $message = $e->getMessage(); - utils\CLI::print_warning( - "server sent error '{$message}' with code '{$code}' for '{$asset['id']}'" - . " - retrying in '{$timer}' seconds" - ); + $print = "server sent error '{$message}' with code '{$code}' for '{$asset['id']}'" + . " - retrying in '{$timer}' seconds"; + + switch ($code) { + // CoinGecko's unrecoverable error (paid plan needed) + case 10012: + utils\CLI::throw_fatal($print); + break; + default: + utils\CLI::print_warning($print); + break; + } $i = 1; $j = 1;