@@ -162,25 +162,18 @@ export const install = async (pluginName: string, cb:Function|null = null) => {
162
162
export let availablePlugins :MapArrayType < PackageInfo > | null = null ;
163
163
let cacheTimestamp = 0 ;
164
164
165
- export const getAvailablePlugins = ( maxCacheAge : number | false ) => {
165
+ export const getAvailablePlugins = async ( maxCacheAge : number | false ) => {
166
166
const nowTimestamp = Math . round ( Date . now ( ) / 1000 ) ;
167
167
168
- return new Promise < MapArrayType < PackageInfo > > ( async ( resolve , reject ) => {
169
- // check cache age before making any request
170
- if ( availablePlugins && maxCacheAge && ( nowTimestamp - cacheTimestamp ) <= maxCacheAge ) {
171
- return resolve ( availablePlugins ) ;
172
- }
168
+ // check cache age before making any request
169
+ if ( availablePlugins && maxCacheAge && ( nowTimestamp - cacheTimestamp ) <= maxCacheAge ) {
170
+ return availablePlugins ;
171
+ }
173
172
174
- await axios . get ( `${ settings . updateServer } /plugins.json` , { headers} )
175
- . then ( ( pluginsLoaded : AxiosResponse < MapArrayType < PackageInfo > > ) => {
176
- availablePlugins = pluginsLoaded . data ;
177
- cacheTimestamp = nowTimestamp ;
178
- resolve ( availablePlugins ) ;
179
- } )
180
- . catch ( async ( err ) => {
181
- logger . error ( `Error fetching available plugins: ${ err } ` ) ;
182
- } ) ;
183
- } ) ;
173
+ const pluginsLoaded : AxiosResponse < MapArrayType < PackageInfo > > = await axios . get ( `${ settings . updateServer } /plugins.json` , { headers} )
174
+ availablePlugins = pluginsLoaded . data ;
175
+ cacheTimestamp = nowTimestamp ;
176
+ return availablePlugins ;
184
177
} ;
185
178
186
179
@@ -213,4 +206,7 @@ export const search = (searchTerm: string, maxCacheAge: number) => getAvailableP
213
206
214
207
return res ;
215
208
}
216
- ) ;
209
+ ) . catch ( ( err ) => {
210
+ logger . error ( `Error searching plugins: ${ err } ` ) ;
211
+ return { } as MapArrayType < PackageInfo > ;
212
+ } ) ;
0 commit comments