File tree Expand file tree Collapse file tree 2 files changed +46
-5
lines changed Expand file tree Collapse file tree 2 files changed +46
-5
lines changed Original file line number Diff line number Diff line change @@ -14,12 +14,23 @@ const internals = {};
14
14
15
15
internals . createPackageLoader = async ( packageName ) => {
16
16
17
- const packument = await Pacote . packument ( packageName + '@latest' , {
18
- 'fullMetadata' : true ,
19
- 'user-agent' : `${ Package . name } @${ Package . version } , see ${ Package . homepage } `
20
- } ) ;
17
+ try {
18
+ const packument = await Pacote . packument ( packageName + '@latest' , {
19
+ 'fullMetadata' : true ,
20
+ 'user-agent' : `${ Package . name } @${ Package . version } , see ${ Package . homepage } `
21
+ } ) ;
21
22
22
- return internals . createRepositoryLoader ( packument . repository . url ) ;
23
+ return internals . createRepositoryLoader ( packument . repository . url ) ;
24
+ }
25
+ catch ( err ) {
26
+
27
+ if ( err . statusCode === 404 ) {
28
+ throw new Error ( `Package ${ packageName } does not exist` ) ;
29
+ }
30
+
31
+ throw err ;
32
+
33
+ }
23
34
} ;
24
35
25
36
Original file line number Diff line number Diff line change @@ -498,6 +498,36 @@ describe('node-support', () => {
498
498
engines : '>=10'
499
499
} ) ;
500
500
} ) ;
501
+
502
+ it ( 'throws when package does not exist in the registry' , async ( ) => {
503
+
504
+ Nock ( 'https://registry.npmjs.org' )
505
+ . get ( '/node-support' )
506
+ . reply ( 404 ) ;
507
+
508
+ await expect ( NodeSupport . detect ( { packageName : 'node-support' } ) )
509
+ . to . reject ( `Package node-support does not exist` ) ;
510
+ } ) ;
511
+
512
+ it ( 'rethrows registry server errors' , async ( ) => {
513
+
514
+ Nock ( 'https://registry.npmjs.org' )
515
+ . get ( '/node-support' )
516
+ . reply ( 500 ) ;
517
+
518
+ await expect ( NodeSupport . detect ( { packageName : 'node-support' } ) )
519
+ . to . reject ( / I n t e r n a l S e r v e r E r r o r / ) ;
520
+ } ) ;
521
+
522
+ it ( 'rethrows generic errors' , async ( ) => {
523
+
524
+ const err = new Error ( 'Something went wrong' ) ;
525
+
526
+ Sinon . stub ( Wreck , 'get' ) . throws ( err ) ;
527
+
528
+ await expect ( NodeSupport . detect ( { packageName : 'node-support' } ) )
529
+ . to . reject ( 'Something went wrong' ) ;
530
+ } ) ;
501
531
} ) ;
502
532
} ) ;
503
533
} ) ;
You can’t perform that action at this time.
0 commit comments