Merge pull request #161 from ltctceplrm/api-checl
Fixed bug when API key is missing
This commit is contained in:
commit
7ae05b03c1
2 changed files with 15 additions and 3 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { APIModel } from '../APIModel';
|
||||
import { Notice } from 'obsidian';
|
||||
import { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||
import MediaDbPlugin from '../../main';
|
||||
import { GameModel } from '../../models/GameModel';
|
||||
|
|
@ -22,7 +23,9 @@ export class MobyGamesAPI extends APIModel {
|
|||
console.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
|
||||
if (!this.plugin.settings.MobyGamesKey) {
|
||||
throw Error(`MDB | API key for ${this.apiName} missing.`);
|
||||
console.error(new Error(`MDB | API key for ${this.apiName} missing.`));
|
||||
new Notice(`MediaDB | API key for ${this.apiName} missing.`);
|
||||
return [];
|
||||
}
|
||||
|
||||
const searchUrl = `${this.apiUrl}/games?title=${encodeURIComponent(title)}&api_key=${this.plugin.settings.MobyGamesKey}`;
|
||||
|
|
@ -65,6 +68,7 @@ export class MobyGamesAPI extends APIModel {
|
|||
console.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
|
||||
if (!this.plugin.settings.MobyGamesKey) {
|
||||
new Notice(`MediaDB | API key for ${this.apiName} missing.`);
|
||||
throw Error(`MDB | API key for ${this.apiName} missing.`);
|
||||
}
|
||||
|
||||
|
|
@ -75,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}.`);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { APIModel } from '../APIModel';
|
||||
import { Notice } from 'obsidian';
|
||||
import { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||
import { MovieModel } from '../../models/MovieModel';
|
||||
import MediaDbPlugin from '../../main';
|
||||
|
|
@ -29,7 +30,9 @@ export class OMDbAPI extends APIModel {
|
|||
console.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
|
||||
if (!this.plugin.settings.OMDbKey) {
|
||||
throw Error(`MDB | API key for ${this.apiName} missing.`);
|
||||
console.error(new Error(`MDB | API key for ${this.apiName} missing.`));
|
||||
new Notice(`MediaDB | API key for ${this.apiName} missing.`);
|
||||
return [];
|
||||
}
|
||||
|
||||
const searchUrl = `https://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`;
|
||||
|
|
@ -107,6 +110,7 @@ export class OMDbAPI extends APIModel {
|
|||
console.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
|
||||
if (!this.plugin.settings.OMDbKey) {
|
||||
new Notice(`MediaDB | API key for ${this.apiName} missing.`);
|
||||
throw Error(`MDB | API key for ${this.apiName} missing.`);
|
||||
}
|
||||
|
||||
|
|
@ -114,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}.`);
|
||||
}
|
||||
|
||||
|
|
@ -124,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}`);
|
||||
}
|
||||
|
||||
|
|
@ -222,4 +229,4 @@ export class OMDbAPI extends APIModel {
|
|||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue