11import { APIModel } from '../APIModel' ;
2+ import { Notice } from 'obsidian' ;
23import { MediaTypeModel } from '../../models/MediaTypeModel' ;
34import { MovieModel } from '../../models/MovieModel' ;
45import MediaDbPlugin from '../../main' ;
@@ -29,7 +30,9 @@ export class OMDbAPI extends APIModel {
2930 console . log ( `MDB | api "${ this . apiName } " queried by Title` ) ;
3031
3132 if ( ! this . plugin . settings . OMDbKey ) {
32- throw Error ( `MDB | API key for ${ this . apiName } missing.` ) ;
33+ console . error ( new Error ( `MDB | API key for ${ this . apiName } missing.` ) ) ;
34+ new Notice ( `MediaDB | API key for ${ this . apiName } missing.` ) ;
35+ return [ ] ;
3336 }
3437
3538 const searchUrl = `https://www.omdbapi.com/?s=${ encodeURIComponent ( title ) } &apikey=${ this . plugin . settings . OMDbKey } ` ;
@@ -107,23 +110,27 @@ export class OMDbAPI extends APIModel {
107110 console . log ( `MDB | api "${ this . apiName } " queried by ID` ) ;
108111
109112 if ( ! this . plugin . settings . OMDbKey ) {
113+ new Notice ( `MediaDB | API key for ${ this . apiName } missing.` ) ;
110114 throw Error ( `MDB | API key for ${ this . apiName } missing.` ) ;
111115 }
112116
113117 const searchUrl = `https://www.omdbapi.com/?i=${ encodeURIComponent ( id ) } &apikey=${ this . plugin . settings . OMDbKey } ` ;
114118 const fetchData = await fetch ( searchUrl ) ;
115119
116120 if ( fetchData . status === 401 ) {
121+ new Notice ( `MDB | Authentication for ${ this . apiName } failed. Check the API key.` ) ;
117122 throw Error ( `MDB | Authentication for ${ this . apiName } failed. Check the API key.` ) ;
118123 }
119124 if ( fetchData . status !== 200 ) {
125+ new Notice ( `MDB | Received status code ${ fetchData . status } from ${ this . apiName } .` ) ;
120126 throw Error ( `MDB | Received status code ${ fetchData . status } from ${ this . apiName } .` ) ;
121127 }
122128
123129 const result = await fetchData . json ( ) ;
124130 // console.debug(result);
125131
126132 if ( result . Response === 'False' ) {
133+ new Notice ( `MDB | Received error from ${ this . apiName } : ${ result . Error } ` ) ;
127134 throw Error ( `MDB | Received error from ${ this . apiName } : ${ result . Error } ` ) ;
128135 }
129136
@@ -222,4 +229,4 @@ export class OMDbAPI extends APIModel {
222229
223230 return ;
224231 }
225- }
232+ }
0 commit comments