From 2dc37906fd1d5e2d1a13a3e411b987a66ac17245 Mon Sep 17 00:00:00 2001 From: ltctceplrm <14954927+ltctceplrm@users.noreply.github.com> Date: Wed, 4 Sep 2024 13:40:39 +0200 Subject: [PATCH] Added more notices when an API errors out So users know what went wrong without going to the console --- src/api/apis/MobyGamesAPI.ts | 1 + src/api/apis/OMDbAPI.ts | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/api/apis/MobyGamesAPI.ts b/src/api/apis/MobyGamesAPI.ts index 93cd4a2..14e42c6 100644 --- a/src/api/apis/MobyGamesAPI.ts +++ b/src/api/apis/MobyGamesAPI.ts @@ -79,6 +79,7 @@ export class MobyGamesAPI extends APIModel { console.debug(fetchData); if (fetchData.status !== 200) { + new Notice(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`); throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`); } diff --git a/src/api/apis/OMDbAPI.ts b/src/api/apis/OMDbAPI.ts index ab0e95d..451961a 100644 --- a/src/api/apis/OMDbAPI.ts +++ b/src/api/apis/OMDbAPI.ts @@ -118,9 +118,11 @@ export class OMDbAPI extends APIModel { const fetchData = await fetch(searchUrl); if (fetchData.status === 401) { + new Notice(`MDB | Authentication for ${this.apiName} failed. Check the API key.`); throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`); } if (fetchData.status !== 200) { + new Notice(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`); throw Error(`MDB | Received status code ${fetchData.status} from ${this.apiName}.`); } @@ -128,6 +130,7 @@ export class OMDbAPI extends APIModel { // console.debug(result); if (result.Response === 'False') { + new Notice(`MDB | Received error from ${this.apiName}: ${result.Error}`); throw Error(`MDB | Received error from ${this.apiName}: ${result.Error}`); }