@@ -413,15 +413,24 @@ async def fetch_cves(self):
413
413
self .nist_fetch_using_api (),
414
414
)
415
415
else :
416
- nvd_metadata = await asyncio .create_task (
417
- self .nist_scrape (self .session ),
418
- )
416
+ try :
417
+ nvd_metadata = await asyncio .create_task (
418
+ self .nist_scrape (self .session ),
419
+ )
420
+
421
+ tasks = [
422
+ self .cache_update (self .session , url , meta ["sha256" ])
423
+ for url , meta in nvd_metadata .items ()
424
+ if meta is not None
425
+ ]
426
+ except Exception as e :
427
+ self .nvd_type = "api2"
428
+ self .feed = self .FEED_MIRROR
429
+ self .LOGGER .info ("NVD appears to be down, falling back to mirror" )
430
+ self .all_cve_entries = await asyncio .create_task (
431
+ self .nist_fetch_using_api (),
432
+ )
419
433
420
- tasks = [
421
- self .cache_update (self .session , url , meta ["sha256" ])
422
- for url , meta in nvd_metadata .items ()
423
- if meta is not None
424
- ]
425
434
426
435
total_tasks = len (tasks )
427
436
@@ -464,14 +473,17 @@ async def nist_fetch_using_api(self) -> list:
464
473
api_key = self .nvd_api_key ,
465
474
api_version = api_version ,
466
475
)
467
- if self .incremental_update :
468
- await nvd_api .get_nvd_params (
469
- time_of_last_update = datetime .datetime .fromtimestamp (
470
- db .get_db_update_date ()
476
+ try :
477
+ if self .incremental_update :
478
+ await nvd_api .get_nvd_params (
479
+ time_of_last_update = datetime .datetime .fromtimestamp (
480
+ db .get_db_update_date ()
481
+ )
471
482
)
472
- )
473
- else :
474
- await nvd_api .get_nvd_params ()
483
+ else :
484
+ await nvd_api .get_nvd_params ()
485
+ except Exception as e :
486
+ self .LOGGER .debug (f"{ e } " )
475
487
await nvd_api .get ()
476
488
await nvd_api .session .close ()
477
489
nvd_api .session = None
0 commit comments