flitrx commited on
Commit
bd3a38e
·
verified ·
1 Parent(s): f9cd923

review debug output and try to fix issiue - Follow Up Deployment

Browse files
Files changed (1) hide show
  1. index.html +43 -10
index.html CHANGED
@@ -217,7 +217,8 @@
217
  const apiConfig = {
218
  api_key: "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",
219
  base_url: "https://openrouter.ai/api/v1",
220
- model: "cognitivecomputations/dolphin-mistral-24b-venice-edition:free"
 
221
  };
222
 
223
  const systemPrompt = `You are an expert in cybersecurity and Google dorking.
@@ -259,7 +260,11 @@
259
  `;
260
 
261
  try {
 
 
 
262
  const response = await fetch(`${apiConfig.base_url}/chat/completions`, {
 
263
  method: 'POST',
264
  headers: {
265
  'Authorization': `Bearer ${apiConfig.api_key}`,
@@ -274,17 +279,31 @@
274
  })
275
  });
276
 
 
277
  const data = await response.json();
278
 
279
- // Check for API errors first
280
- if (data.error) {
281
- throw new Error(data.error.message || 'API Error');
 
 
 
 
 
 
 
 
 
 
282
  }
283
 
284
  // Check response structure
285
- if (!data.choices || !data.choices[0] || !data.choices[0].message || !data.choices[0].message.content) {
286
- console.error('Invalid API response:', data);
287
- throw new Error('Invalid API response format. Please check the console for details.');
 
 
 
288
  }
289
 
290
  // Process dorks
@@ -327,8 +346,12 @@
327
  terminalContent.innerHTML += dorksHTML;
328
 
329
  } catch (error) {
330
- terminalContent.innerHTML += `
331
- <div class="response bg-red-900/50 p-3 rounded border border-red-700">
 
 
 
 
332
  <p class="font-bold text-red-300">Error generating dorks:</p>
333
  <p class="text-red-200">${error.message}</p>
334
  <p class="text-xs text-red-300 mt-2">Please try again or check your API configuration.</p>
@@ -336,11 +359,21 @@
336
  <summary class="cursor-pointer text-red-300">Technical Details</summary>
337
  <pre class="mt-1 p-2 bg-black/50 rounded overflow-auto">${JSON.stringify({
338
  error: error.message,
339
- response: data || 'No response data'
 
 
 
 
 
 
340
  }, null, 2)}</pre>
341
  </details>
 
 
 
342
  </div>
343
  `;
 
344
  }
345
 
346
  // Scroll to bottom and clear input
 
217
  const apiConfig = {
218
  api_key: "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",
219
  base_url: "https://openrouter.ai/api/v1",
220
+ model: "cognitivecomputations/dolphin-mistral-24b-venice-edition:free",
221
+ debug: true // Enable debug logging
222
  };
223
 
224
  const systemPrompt = `You are an expert in cybersecurity and Google dorking.
 
260
  `;
261
 
262
  try {
263
+ const controller = new AbortController();
264
+ const timeoutId = setTimeout(() => controller.abort(), 15000); // 15 second timeout
265
+
266
  const response = await fetch(`${apiConfig.base_url}/chat/completions`, {
267
+ signal: controller.signal,
268
  method: 'POST',
269
  headers: {
270
  'Authorization': `Bearer ${apiConfig.api_key}`,
 
279
  })
280
  });
281
 
282
+ clearTimeout(timeoutId);
283
  const data = await response.json();
284
 
285
+ if (apiConfig.debug) {
286
+ console.log('Full API Response:', data);
287
+ console.log('Response Status:', response.status);
288
+ console.log('Response Headers:', Object.fromEntries(response.headers.entries()));
289
+ }
290
+
291
+ if (!response.ok) {
292
+ const errorData = await response.json().catch(() => ({}));
293
+ console.error('API Error Response:', errorData);
294
+ throw new Error(
295
+ errorData.error?.message ||
296
+ `API request failed with status ${response.status}: ${response.statusText}`
297
+ );
298
  }
299
 
300
  // Check response structure
301
+ if (!data.choices?.[0]?.message?.content) {
302
+ console.error('Invalid API response structure:', data);
303
+ throw new Error(
304
+ `Invalid API response format. Expected choices[0].message.content. ` +
305
+ `Received: ${JSON.stringify(data, null, 2)}`
306
+ );
307
  }
308
 
309
  // Process dorks
 
346
  terminalContent.innerHTML += dorksHTML;
347
 
348
  } catch (error) {
349
+ console.error('Error in API call:', error);
350
+ let errorHtml = `
351
+ <div class="response bg-red-900/50 p-3 rounded border border-red-700 mb-4">
352
+ <div class="flex items-start">
353
+ <i class="fas fa-exclamation-triangle text-red-300 mr-2 mt-1"></i>
354
+ <div>
355
  <p class="font-bold text-red-300">Error generating dorks:</p>
356
  <p class="text-red-200">${error.message}</p>
357
  <p class="text-xs text-red-300 mt-2">Please try again or check your API configuration.</p>
 
359
  <summary class="cursor-pointer text-red-300">Technical Details</summary>
360
  <pre class="mt-1 p-2 bg-black/50 rounded overflow-auto">${JSON.stringify({
361
  error: error.message,
362
+ stack: error.stack,
363
+ response: data || 'No response data',
364
+ request: {
365
+ url: `${apiConfig.base_url}/chat/completions`,
366
+ model: apiConfig.model,
367
+ prompt: `${query} ${numDorks}`
368
+ }
369
  }, null, 2)}</pre>
370
  </details>
371
+ <button onclick="window.location.reload()" class="mt-3 px-3 py-1 bg-blue-600 hover:bg-blue-700 rounded text-sm">
372
+ <i class="fas fa-sync-alt mr-1"></i> Retry
373
+ </button>
374
  </div>
375
  `;
376
+ terminalContent.innerHTML += errorHtml;
377
  }
378
 
379
  // Scroll to bottom and clear input