1
1
import { APIModel } from '../APIModel' ;
2
+ import { Notice } from 'obsidian' ;
2
3
import { MediaTypeModel } from '../../models/MediaTypeModel' ;
3
4
import { MovieModel } from '../../models/MovieModel' ;
4
5
import MediaDbPlugin from '../../main' ;
@@ -29,7 +30,9 @@ export class OMDbAPI extends APIModel {
29
30
console . log ( `MDB | api "${ this . apiName } " queried by Title` ) ;
30
31
31
32
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 [ ] ;
33
36
}
34
37
35
38
const searchUrl = `https://www.omdbapi.com/?s=${ encodeURIComponent ( title ) } &apikey=${ this . plugin . settings . OMDbKey } ` ;
@@ -107,23 +110,27 @@ export class OMDbAPI extends APIModel {
107
110
console . log ( `MDB | api "${ this . apiName } " queried by ID` ) ;
108
111
109
112
if ( ! this . plugin . settings . OMDbKey ) {
113
+ new Notice ( `MediaDB | API key for ${ this . apiName } missing.` ) ;
110
114
throw Error ( `MDB | API key for ${ this . apiName } missing.` ) ;
111
115
}
112
116
113
117
const searchUrl = `https://www.omdbapi.com/?i=${ encodeURIComponent ( id ) } &apikey=${ this . plugin . settings . OMDbKey } ` ;
114
118
const fetchData = await fetch ( searchUrl ) ;
115
119
116
120
if ( fetchData . status === 401 ) {
121
+ new Notice ( `MDB | Authentication for ${ this . apiName } failed. Check the API key.` ) ;
117
122
throw Error ( `MDB | Authentication for ${ this . apiName } failed. Check the API key.` ) ;
118
123
}
119
124
if ( fetchData . status !== 200 ) {
125
+ new Notice ( `MDB | Received status code ${ fetchData . status } from ${ this . apiName } .` ) ;
120
126
throw Error ( `MDB | Received status code ${ fetchData . status } from ${ this . apiName } .` ) ;
121
127
}
122
128
123
129
const result = await fetchData . json ( ) ;
124
130
// console.debug(result);
125
131
126
132
if ( result . Response === 'False' ) {
133
+ new Notice ( `MDB | Received error from ${ this . apiName } : ${ result . Error } ` ) ;
127
134
throw Error ( `MDB | Received error from ${ this . apiName } : ${ result . Error } ` ) ;
128
135
}
129
136
@@ -222,4 +229,4 @@ export class OMDbAPI extends APIModel {
222
229
223
230
return ;
224
231
}
225
- }
232
+ }
0 commit comments