Skip to content

Commit b856c18

Browse files
committed
Don't search APIs that require keys if no key is present
1 parent 8deaedc commit b856c18

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/api/apis/MobyGamesAPI.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export class MobyGamesAPI extends APIModel {
2121
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
2222
console.log(`MDB | api "${this.apiName}" queried by Title`);
2323

24+
if(!this.plugin.settings.MobyGamesKey) {
25+
throw Error(`MDB | MobyGames ${this.apiName} API key missing.`);
26+
}
27+
2428
const searchUrl = `${this.apiUrl}/games?title=${encodeURIComponent(title)}&api_key=${this.plugin.settings.MobyGamesKey}`;
2529
const fetchData = await requestUrl({
2630
url: searchUrl,
@@ -60,6 +64,10 @@ export class MobyGamesAPI extends APIModel {
6064
async getById(id: string): Promise<MediaTypeModel> {
6165
console.log(`MDB | api "${this.apiName}" queried by ID`);
6266

67+
if(!this.plugin.settings.MobyGamesKey) {
68+
throw Error(`MDB | MobyGames ${this.apiName} API key missing.`);
69+
}
70+
6371
const searchUrl = `${this.apiUrl}/games?id=${encodeURIComponent(id)}&api_key=${this.plugin.settings.MobyGamesKey}`;
6472
const fetchData = await requestUrl({
6573
url: searchUrl,

src/api/apis/OMDbAPI.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export class OMDbAPI extends APIModel {
2828
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
2929
console.log(`MDB | api "${this.apiName}" queried by Title`);
3030

31+
if(!this.plugin.settings.OMDbKey) {
32+
throw Error(`MDB | OMDb ${this.apiName} API key missing.`);
33+
}
34+
3135
const searchUrl = `http://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`;
3236
const fetchData = await fetch(searchUrl);
3337

@@ -102,6 +106,10 @@ export class OMDbAPI extends APIModel {
102106
async getById(id: string): Promise<MediaTypeModel> {
103107
console.log(`MDB | api "${this.apiName}" queried by ID`);
104108

109+
if(!this.plugin.settings.OMDbKey) {
110+
throw Error(`MDB | OMDb ${this.apiName} API key missing.`);
111+
}
112+
105113
const searchUrl = `http://www.omdbapi.com/?i=${encodeURIComponent(id)}&apikey=${this.plugin.settings.OMDbKey}`;
106114
const fetchData = await fetch(searchUrl);
107115

0 commit comments

Comments
 (0)