Don't search APIs that require keys if no key is present

This commit is contained in:
Zack Boehm 2024-06-03 01:51:27 -04:00
parent 8deaedc592
commit b856c18207
2 changed files with 16 additions and 0 deletions

View file

@ -28,6 +28,10 @@ export class OMDbAPI extends APIModel {
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
console.log(`MDB | api "${this.apiName}" queried by Title`);
if(!this.plugin.settings.OMDbKey) {
throw Error(`MDB | OMDb ${this.apiName} API key missing.`);
}
const searchUrl = `http://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`;
const fetchData = await fetch(searchUrl);
@ -102,6 +106,10 @@ export class OMDbAPI extends APIModel {
async getById(id: string): Promise<MediaTypeModel> {
console.log(`MDB | api "${this.apiName}" queried by ID`);
if(!this.plugin.settings.OMDbKey) {
throw Error(`MDB | OMDb ${this.apiName} API key missing.`);
}
const searchUrl = `http://www.omdbapi.com/?i=${encodeURIComponent(id)}&apikey=${this.plugin.settings.OMDbKey}`;
const fetchData = await fetch(searchUrl);