@@ -3,6 +3,7 @@ document.addEventListener("DOMContentLoaded", () => {
33 async function getMyIP ( ) {
44 try {
55 const response = await fetch ( "https://api.ipify.org?format=json" ) ;
6+ if ( ! response . ok ) throw new Error ( "Failed to fetch" ) ;
67 const data = await response . json ( ) ;
78 document . getElementById ( "my-ip" ) . textContent = `Your IP: ${ data . ip } ` ;
89 } catch ( error ) {
@@ -22,6 +23,7 @@ document.addEventListener("DOMContentLoaded", () => {
2223 showLoading ( ) ;
2324 const aiPrediction = await getAIIPPrediction ( ip ) ; // AI-based prediction
2425 const response = await fetch ( `https://ip-api.com/json/${ ip } ` ) ;
26+ if ( ! response . ok ) throw new Error ( "Failed to fetch" ) ;
2527 const data = await response . json ( ) ;
2628 if ( data . status === "success" ) {
2729 document . getElementById ( "ip-info" ) . textContent =
@@ -39,10 +41,16 @@ document.addEventListener("DOMContentLoaded", () => {
3941
4042 // AI-based IP Prediction (AI model can be integrated here)
4143 async function getAIIPPrediction ( ip ) {
42- const aiApi = "https://your-ai-api.com/predict" ; // Your AI API endpoint
43- const response = await fetch ( `${ aiApi } ?ip=${ ip } ` ) ;
44- const data = await response . json ( ) ;
45- return data . prediction ; // AI's predicted location or data
44+ try {
45+ const aiApi = "https://your-ai-api.com/predict" ; // Your AI API endpoint
46+ const response = await fetch ( `${ aiApi } ?ip=${ ip } ` ) ;
47+ if ( ! response . ok ) throw new Error ( "Failed to fetch AI prediction" ) ;
48+ const data = await response . json ( ) ;
49+ return data . prediction ; // AI's predicted location or data
50+ } catch ( error ) {
51+ console . error ( "Error in AI Prediction:" , error ) ;
52+ return "Unavailable" ;
53+ }
4654 }
4755
4856 // Internet Speed Test with AI optimization
@@ -74,7 +82,8 @@ document.addEventListener("DOMContentLoaded", () => {
7482 }
7583 const start = Date . now ( ) ;
7684 try {
77- await fetch ( url , { method : "HEAD" } ) ;
85+ const response = await fetch ( url , { method : "HEAD" } ) ;
86+ if ( ! response . ok ) throw new Error ( "Ping failed" ) ;
7887 const end = Date . now ( ) ;
7988 document . getElementById ( "ping-results" ) . textContent =
8089 `Ping: ${ end - start } ms` ;
0 commit comments