KiWA001 commited on
Commit
022553c
·
1 Parent(s): 609d661

Fix API key lookup error handling - properly parse and display error messages

Browse files

The error '[object Object]' was occurring because:
- Error response wasn't being properly parsed as JSON
- Error object was being displayed without string conversion

Fixed in all 3 files (docs.html, public_docs.html, qaz.html):
- Wrapped JSON parsing in try-catch
- Try multiple error fields (detail, message, stringify object)
- Properly convert error to string in catch block
- Fallback to 'Key not found or server error' if parsing fails

Now shows actual error message instead of '[object Object]'

Files changed (3) hide show
  1. static/docs.html +10 -3
  2. static/public_docs.html +10 -3
  3. static/qaz.html +10 -3
static/docs.html CHANGED
@@ -1017,8 +1017,14 @@
1017
  });
1018
 
1019
  if (!res.ok) {
1020
- const error = await res.json();
1021
- throw new Error(error.detail || 'Key not found');
 
 
 
 
 
 
1022
  }
1023
 
1024
  const data = await res.json();
@@ -1057,7 +1063,8 @@
1057
 
1058
  } catch (e) {
1059
  errorDiv.style.display = 'block';
1060
- errorDiv.textContent = 'Error: ' + e.message;
 
1061
  resultDiv.style.display = 'none';
1062
  }
1063
  }
 
1017
  });
1018
 
1019
  if (!res.ok) {
1020
+ let errorMessage = 'Key not found';
1021
+ try {
1022
+ const error = await res.json();
1023
+ errorMessage = error.detail || error.message || JSON.stringify(error) || 'Key not found';
1024
+ } catch (parseError) {
1025
+ errorMessage = 'Key not found or server error';
1026
+ }
1027
+ throw new Error(errorMessage);
1028
  }
1029
 
1030
  const data = await res.json();
 
1063
 
1064
  } catch (e) {
1065
  errorDiv.style.display = 'block';
1066
+ const errorMsg = e.message || (typeof e === 'object' ? JSON.stringify(e) : String(e));
1067
+ errorDiv.textContent = 'Error: ' + errorMsg;
1068
  resultDiv.style.display = 'none';
1069
  }
1070
  }
static/public_docs.html CHANGED
@@ -747,8 +747,14 @@
747
  });
748
 
749
  if (!res.ok) {
750
- const error = await res.json();
751
- throw new Error(error.detail || 'Key not found');
 
 
 
 
 
 
752
  }
753
 
754
  const data = await res.json();
@@ -787,7 +793,8 @@
787
 
788
  } catch (e) {
789
  errorDiv.style.display = 'block';
790
- errorDiv.textContent = 'Error: ' + e.message;
 
791
  resultDiv.style.display = 'none';
792
  }
793
  }
 
747
  });
748
 
749
  if (!res.ok) {
750
+ let errorMessage = 'Key not found';
751
+ try {
752
+ const error = await res.json();
753
+ errorMessage = error.detail || error.message || JSON.stringify(error) || 'Key not found';
754
+ } catch (parseError) {
755
+ errorMessage = 'Key not found or server error';
756
+ }
757
+ throw new Error(errorMessage);
758
  }
759
 
760
  const data = await res.json();
 
793
 
794
  } catch (e) {
795
  errorDiv.style.display = 'block';
796
+ const errorMsg = e.message || (typeof e === 'object' ? JSON.stringify(e) : String(e));
797
+ errorDiv.textContent = 'Error: ' + errorMsg;
798
  resultDiv.style.display = 'none';
799
  }
800
  }
static/qaz.html CHANGED
@@ -463,8 +463,14 @@
463
  });
464
 
465
  if (!res.ok) {
466
- const error = await res.json();
467
- throw new Error(error.detail || 'Key not found');
 
 
 
 
 
 
468
  }
469
 
470
  const data = await res.json();
@@ -503,7 +509,8 @@
503
 
504
  } catch (e) {
505
  errorDiv.style.display = 'block';
506
- errorDiv.textContent = 'Error: ' + e.message;
 
507
  document.getElementById('lookup-name').textContent = 'Not Found';
508
  }
509
  }
 
463
  });
464
 
465
  if (!res.ok) {
466
+ let errorMessage = 'Key not found';
467
+ try {
468
+ const error = await res.json();
469
+ errorMessage = error.detail || error.message || JSON.stringify(error) || 'Key not found';
470
+ } catch (parseError) {
471
+ errorMessage = 'Key not found or server error';
472
+ }
473
+ throw new Error(errorMessage);
474
  }
475
 
476
  const data = await res.json();
 
509
 
510
  } catch (e) {
511
  errorDiv.style.display = 'block';
512
+ const errorMsg = e.message || (typeof e === 'object' ? JSON.stringify(e) : String(e));
513
+ errorDiv.textContent = 'Error: ' + errorMsg;
514
  document.getElementById('lookup-name').textContent = 'Not Found';
515
  }
516
  }