From 66bbbc2cb81d8b313b9d16d86348fb86dc6ce902 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Fri, 29 Nov 2024 20:21:46 +0100 Subject: [PATCH] Feature/improve error handling in Ghostfolio data provider (#4079) * Improve error handling --- .../ghostfolio/ghostfolio.service.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/apps/api/src/services/data-provider/ghostfolio/ghostfolio.service.ts b/apps/api/src/services/data-provider/ghostfolio/ghostfolio.service.ts index acd66b0af..5be7d8312 100644 --- a/apps/api/src/services/data-provider/ghostfolio/ghostfolio.service.ts +++ b/apps/api/src/services/data-provider/ghostfolio/ghostfolio.service.ts @@ -28,6 +28,7 @@ import { Injectable, Logger } from '@nestjs/common'; import { DataSource, SymbolProfile } from '@prisma/client'; import { format } from 'date-fns'; import got from 'got'; +import { StatusCodes } from 'http-status-codes'; @Injectable() export class GhostfolioService implements DataProviderInterface { @@ -106,6 +107,17 @@ export class GhostfolioService implements DataProviderInterface { [symbol]: historicalData }; } catch (error) { + let message = error; + + if (error.response?.statusCode === StatusCodes.TOO_MANY_REQUESTS) { + message = 'RequestError: The daily request limit has been exceeded'; + } else if (error.response?.statusCode === StatusCodes.UNAUTHORIZED) { + message = + 'RequestError: The provided API key is invalid. Please update it in the Settings section of the Admin Control panel.'; + } + + Logger.error(message, 'GhostfolioService'); + throw new Error( `Could not get historical market data for ${symbol} (${this.getName()}) from ${format( from, @@ -159,6 +171,11 @@ export class GhostfolioService implements DataProviderInterface { message = `RequestError: The operation to get the quotes was aborted because the request to the data provider took more than ${( this.configurationService.get('REQUEST_TIMEOUT') / 1000 ).toFixed(3)} seconds`; + } else if (error.response?.statusCode === StatusCodes.TOO_MANY_REQUESTS) { + message = 'RequestError: The daily request limit has been exceeded'; + } else if (error.response?.statusCode === StatusCodes.UNAUTHORIZED) { + message = + 'RequestError: The provided API key is invalid. Please update it in the Settings section of the Admin Control panel.'; } Logger.error(message, 'GhostfolioService'); @@ -196,6 +213,11 @@ export class GhostfolioService implements DataProviderInterface { message = `RequestError: The operation to search for ${query} was aborted because the request to the data provider took more than ${( this.configurationService.get('REQUEST_TIMEOUT') / 1000 ).toFixed(3)} seconds`; + } else if (error.response?.statusCode === StatusCodes.TOO_MANY_REQUESTS) { + message = 'RequestError: The daily request limit has been exceeded'; + } else if (error.response?.statusCode === StatusCodes.UNAUTHORIZED) { + message = + 'RequestError: The provided API key is invalid. Please update it in the Settings section of the Admin Control panel.'; } Logger.error(message, 'GhostfolioService');