11import { binarySearch } from './functions/binarySearch.js'
22import { fetchArrayBuffer } from './functions/fetchArrayBuffer.js'
3+ import { log } from './functions/log.js'
34import { numberToCountryCode } from './functions/numberToCountryCode.js'
45import { numberToDir } from './functions/numberToDir.js'
56import { parseIp } from './functions/parseIp.js'
@@ -32,13 +33,15 @@ export function setup<T extends 'country' | 'geocode'>(): (ipInput: string) => P
3233 //* Get the index for the IP version
3334 const index = INDEXES [ version ] ?? ( await loadIndex ( version ) )
3435 if ( ! index ) {
35- // TODO add debug log
36+ log ( 'warn' , 'No index found' )
3637 return null
3738 }
3839
3940 //* If the IP is less than the first index, return null
40- if ( ! ( ip >= index [ 0 ] ! ) )
41+ if ( ! ( ip >= index [ 0 ] ! ) ) {
42+ log ( 'warn' , `IP ${ ipInput } is out of range` )
4143 return null
44+ }
4245
4346 //* Binary search to find the correct line in the index
4447 const lineIndex = binarySearch ( index , ip )
@@ -51,7 +54,7 @@ export function setup<T extends 'country' | 'geocode'>(): (ipInput: string) => P
5154 new URL ( `${ DATA_URL [ version ] } /indexes/${ version } /${ numberToDir ( lineIndex ) } ` ) ,
5255 )
5356 if ( ! dataResponse ) {
54- // TODO Add debug log
57+ log ( 'warn' , 'Index file not found, is it corrupted?' )
5558 return null
5659 }
5760
@@ -115,8 +118,10 @@ export function setup<T extends 'country' | 'geocode'>(): (ipInput: string) => P
115118 const result = await fetchArrayBuffer (
116119 new URL ( `${ baseUrl } /indexes/${ version } .idx` ) ,
117120 )
118- if ( ! result )
119- return // TODO add debug log
121+ if ( ! result ) {
122+ log ( 'warn' , 'Index file not found, is it corrupted?' )
123+ return null
124+ }
120125
121126 const { versionHeader, buffer } = result
122127 if ( versionHeader )
0 commit comments