Compare commits

..

1 Commits

Author SHA1 Message Date
f766451f13 More informative error message in case search returned an error 2025-06-24 07:34:17 +03:00

View File

@ -202,23 +202,7 @@ h1 {
<script>
window.addEventListener('load', function() {
function extractText(responseText) {
try {
console.log('responseText: ', responseText);
const results = JSON.parse(responseText);
const msg = results.message;
if (!msg || msg.trim() === '') {
return "No results found";
}
return msg;
} catch (error) {
console.error('Error parsing results:', error);
throw new Error("Failed parsing response message");
}
}
function displayResults(msg) {
function displayResults(responseText) {
const resultsContainer = document.getElementById('results');
const spinner = document.getElementById('spinner');
const searchContainer = document.querySelector('.search-container');
@ -230,6 +214,8 @@ window.addEventListener('load', function() {
searchContainer.scrollIntoView({ behavior: 'smooth', block: 'start' });
try {
const results = JSON.parse(responseText);
marked.setOptions({
breaks: true,
gfm: true,
@ -237,7 +223,7 @@ window.addEventListener('load', function() {
sanitize: false
});
const htmlContent = marked.parse(msg);
const htmlContent = marked.parse(results.message);
resultsContainer.className = 'markdown-content';
resultsContainer.innerHTML = htmlContent;
@ -256,7 +242,7 @@ window.addEventListener('load', function() {
}, 100);
} catch (error) {
console.error('Error parsing results:', error);
resultsContainer.innerHTML = '<div class="error-message">Cannot process results</div>';
resultsContainer.innerHTML = '<div class="error-message">Error processing results</div>';
}
}
@ -289,25 +275,24 @@ window.addEventListener('load', function() {
body: JSON.stringify(data)
};
//const API_ENDPOINT = 'http://0.0.0.0:3000/api/v1/docs_help';
// const API_ENDPOINT = 'http://0.0.0.0:3000/api/v1/docs_help';
const API_ENDPOINT = 'https://help.merge.qodo.ai/api/v1/docs_help';
const response = await fetch(API_ENDPOINT, options);
const responseText = await response.text();
const msg = extractText(responseText);
if (!response.ok) {
throw new Error(`An error (${response.status}) occurred during search: "${msg}"`);
throw new Error(`HTTP error! status: ${response.status}`);
}
displayResults(msg);
const responseText = await response.text();
displayResults(responseText);
} catch (error) {
spinner.style.display = 'none';
const errorDiv = document.createElement('div');
errorDiv.className = 'error-message';
errorDiv.textContent = `${error}`;
resultsContainer.value = "";
resultsContainer.appendChild(errorDiv);
resultsContainer.innerHTML = `
<div class="error-message">
No results found. Please try again.
</div>
`;
}
}