diff --git a/src/api/apis/MobyGamesAPI.ts b/src/api/apis/MobyGamesAPI.ts index e14c5c9..98cae47 100644 --- a/src/api/apis/MobyGamesAPI.ts +++ b/src/api/apis/MobyGamesAPI.ts @@ -21,6 +21,10 @@ export class MobyGamesAPI extends APIModel { async searchByTitle(title: string): Promise { console.log(`MDB | api "${this.apiName}" queried by Title`); + if(!this.plugin.settings.MobyGamesKey) { + throw Error(`MDB | ${this.apiName} API key missing.`); + } + const searchUrl = `${this.apiUrl}/games?title=${encodeURIComponent(title)}&api_key=${this.plugin.settings.MobyGamesKey}`; const fetchData = await requestUrl({ url: searchUrl, @@ -60,6 +64,10 @@ export class MobyGamesAPI extends APIModel { async getById(id: string): Promise { console.log(`MDB | api "${this.apiName}" queried by ID`); + if(!this.plugin.settings.MobyGamesKey) { + throw Error(`MDB | ${this.apiName} API key missing.`); + } + const searchUrl = `${this.apiUrl}/games?id=${encodeURIComponent(id)}&api_key=${this.plugin.settings.MobyGamesKey}`; const fetchData = await requestUrl({ url: searchUrl, diff --git a/src/api/apis/OMDbAPI.ts b/src/api/apis/OMDbAPI.ts index 13308f6..b20dcbd 100644 --- a/src/api/apis/OMDbAPI.ts +++ b/src/api/apis/OMDbAPI.ts @@ -17,7 +17,7 @@ export class OMDbAPI extends APIModel { this.plugin = plugin; this.apiName = 'OMDbAPI'; this.apiDescription = 'A free API for Movies, Series and Games.'; - this.apiUrl = 'http://www.omdbapi.com/'; + this.apiUrl = 'https://www.omdbapi.com/'; this.types = [MediaType.Movie, MediaType.Series, MediaType.Game]; this.typeMappings = new Map(); this.typeMappings.set('movie', 'movie'); @@ -28,7 +28,11 @@ export class OMDbAPI extends APIModel { async searchByTitle(title: string): Promise { console.log(`MDB | api "${this.apiName}" queried by Title`); - const searchUrl = `http://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`; + if(!this.plugin.settings.OMDbKey) { + throw Error(`MDB | ${this.apiName} API key missing.`); + } + + const searchUrl = `https://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`; const fetchData = await fetch(searchUrl); if (fetchData.status === 401) { @@ -102,7 +106,11 @@ export class OMDbAPI extends APIModel { async getById(id: string): Promise { console.log(`MDB | api "${this.apiName}" queried by ID`); - const searchUrl = `http://www.omdbapi.com/?i=${encodeURIComponent(id)}&apikey=${this.plugin.settings.OMDbKey}`; + if(!this.plugin.settings.OMDbKey) { + throw Error(`MDB | ${this.apiName} API key missing.`); + } + + const searchUrl = `https://www.omdbapi.com/?i=${encodeURIComponent(id)}&apikey=${this.plugin.settings.OMDbKey}`; const fetchData = await fetch(searchUrl); if (fetchData.status === 401) {