@@ -3,7 +3,7 @@ import { headersWithVirusTotal } from "src/defs/headers";
33import { getDbDomain } from "src/func/db/domain" ;
44import { axios } from "src/utils/axios" ;
55import { db } from "src/utils/db" ;
6- import { sanitizeDomain } from "src/utils/sanitizeDomain" ;
6+ import { sanitizeDomain , validateDomain , DomainValidationError } from "src/utils/sanitizeDomain" ;
77
88/**
99 * A service that provides access to the VirusTotal service for checking and reporting domains.
@@ -19,7 +19,18 @@ export class VirusTotalService {
1919 check : async ( domain : string ) => {
2020 try {
2121 // metrics.increment("services.virustotal.domain.check");
22- const sanitizedDomain = await sanitizeDomain ( domain ) ;
22+ const sanitizedDomain = sanitizeDomain ( domain ) ;
23+
24+ // Validate domain before making API call
25+ try {
26+ await validateDomain ( sanitizedDomain ) ;
27+ } catch ( error ) {
28+ if ( error instanceof DomainValidationError ) {
29+ console . warn ( `VirusTotal: Skipping invalid domain "${ domain } ": ${ error . message } ` ) ;
30+ return null ;
31+ }
32+ throw error ;
33+ }
2334
2435 const response = await axios . get (
2536 `https://www.virustotal.com/api/v3/domains/${ sanitizedDomain } ` ,
@@ -39,9 +50,8 @@ export class VirusTotalService {
3950
4051 return data ;
4152 } catch ( error ) {
42- // Log the error but don't throw
43- // FIXME: this is terrible practice, handle ratelimits better after issue addressed.
44- // console.error(`VirusTotal API error for domain ${domain}:`, error);
53+ // Log the error for transparency, but don't throw to prevent crashes
54+ console . warn ( `VirusTotal API error for domain "${ domain } ":` , error instanceof Error ? error . message : error ) ;
4555 return null ;
4656 }
4757 } ,
@@ -54,7 +64,18 @@ export class VirusTotalService {
5464 */
5565 report : async ( domain : string ) => {
5666 // metrics.increment("services.virustotal.domain.report");
57- const sanitizedDomain = await sanitizeDomain ( domain ) ;
67+ const sanitizedDomain = sanitizeDomain ( domain ) ;
68+
69+ // Validate domain before making API call
70+ try {
71+ await validateDomain ( sanitizedDomain ) ;
72+ } catch ( error ) {
73+ if ( error instanceof DomainValidationError ) {
74+ console . warn ( `VirusTotal: Skipping report for invalid domain "${ domain } ": ${ error . message } ` ) ;
75+ return ;
76+ }
77+ throw error ;
78+ }
5879
5980 const commentData = {
6081 data : {
0 commit comments