Added more notices when an API errors out

So users know what went wrong without going to the console
This commit is contained in:
ltctceplrm 2024-09-04 13:40:39 +02:00
parent 6234677bde
commit 2dc37906fd
2 changed files with 4 additions and 0 deletions

View file

@ -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}`);
}