File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed
Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -292,6 +292,11 @@ export class ElectronVersions extends BaseVersions {
292292 const url = 'https://releases.electronjs.org/releases.json' ;
293293 d ( 'fetching releases list from' , url ) ;
294294 const response = await fetch ( url ) ;
295+ if ( ! response . ok ) {
296+ throw new Error (
297+ `Fetching versions failed with status code: ${ response . status } ` ,
298+ ) ;
299+ }
295300 const json = ( await response . json ( ) ) as unknown ;
296301 await fs . outputJson ( cacheFile , json ) ;
297302 return json ;
@@ -329,6 +334,9 @@ export class ElectronVersions extends BaseVersions {
329334 versions = await ElectronVersions . fetchVersions ( versionsCache ) ;
330335 } catch ( err ) {
331336 d ( 'error fetching versions' , err ) ;
337+ if ( ! versions ) {
338+ throw err ;
339+ }
332340 }
333341 }
334342
Original file line number Diff line number Diff line change @@ -310,12 +310,26 @@ describe('ElectronVersions', () => {
310310 expect ( versions . length ) . toBe ( 2 ) ;
311311 } ) ;
312312
313- it ( 'has no versions with a missing cache and failed fetch' , async ( ) => {
313+ it ( 'throws an error with a missing cache and failed fetch' , async ( ) => {
314314 const scope = nockScope . get ( '/releases.json' ) . replyWithError ( 'Error' ) ;
315315 await fs . remove ( versionsCache ) ;
316- const { versions } = await ElectronVersions . create ( { versionsCache } ) ;
316+ await expect ( ElectronVersions . create ( { versionsCache } ) ) . rejects . toThrow (
317+ Error ,
318+ ) ;
319+ expect ( scope . isDone ( ) ) ;
320+ } ) ;
321+
322+ it ( 'throws an error with a missing cache and a non-200 server response' , async ( ) => {
323+ const scope = nockScope
324+ . get ( '/releases.json' )
325+ . reply ( 500 , JSON . stringify ( { error : true } ) , {
326+ 'Content-Type' : 'application/json' ,
327+ } ) ;
328+ await fs . remove ( versionsCache ) ;
329+ await expect ( ElectronVersions . create ( { versionsCache } ) ) . rejects . toThrow (
330+ Error ,
331+ ) ;
317332 expect ( scope . isDone ( ) ) ;
318- expect ( versions . length ) . toBe ( 0 ) ;
319333 } ) ;
320334
321335 it ( 'fetches with a stale cache' , async ( ) => {
You can’t perform that action at this time.
0 commit comments