mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-02 11:50:37 +08:00
- More informative error message in case search returned an error
- Report no results found in case of an empty response
This commit is contained in:
@ -202,6 +202,21 @@ h1 {
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
window.addEventListener('load', function() {
|
window.addEventListener('load', function() {
|
||||||
|
function extractText(responseText) {
|
||||||
|
try {
|
||||||
|
console.log('responseText: ', responseText);
|
||||||
|
const results = JSON.parse(responseText);
|
||||||
|
msg = results.message;
|
||||||
|
if (!msg || msg.trim() === '') {
|
||||||
|
return "No results found.";
|
||||||
|
}
|
||||||
|
return msg;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error parsing results:', error);
|
||||||
|
throw "Error processing results";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function displayResults(responseText) {
|
function displayResults(responseText) {
|
||||||
const resultsContainer = document.getElementById('results');
|
const resultsContainer = document.getElementById('results');
|
||||||
const spinner = document.getElementById('spinner');
|
const spinner = document.getElementById('spinner');
|
||||||
@ -214,7 +229,7 @@ window.addEventListener('load', function() {
|
|||||||
searchContainer.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
searchContainer.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const results = JSON.parse(responseText);
|
const msg = extractText(responseText)
|
||||||
|
|
||||||
marked.setOptions({
|
marked.setOptions({
|
||||||
breaks: true,
|
breaks: true,
|
||||||
@ -223,7 +238,7 @@ window.addEventListener('load', function() {
|
|||||||
sanitize: false
|
sanitize: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const htmlContent = marked.parse(results.message);
|
const htmlContent = marked.parse(msg);
|
||||||
|
|
||||||
resultsContainer.className = 'markdown-content';
|
resultsContainer.className = 'markdown-content';
|
||||||
resultsContainer.innerHTML = htmlContent;
|
resultsContainer.innerHTML = htmlContent;
|
||||||
@ -275,22 +290,23 @@ window.addEventListener('load', function() {
|
|||||||
body: JSON.stringify(data)
|
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 API_ENDPOINT = 'https://help.merge.qodo.ai/api/v1/docs_help';
|
||||||
|
|
||||||
const response = await fetch(API_ENDPOINT, options);
|
const response = await fetch(API_ENDPOINT, options);
|
||||||
|
const responseText = await response.text();
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
const msg = extractText(responseText);
|
||||||
|
throw new Error(`An error (${response.status}) occurred during search: "${msg}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const responseText = await response.text();
|
|
||||||
displayResults(responseText);
|
displayResults(responseText);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
spinner.style.display = 'none';
|
spinner.style.display = 'none';
|
||||||
resultsContainer.innerHTML = `
|
resultsContainer.innerHTML = `
|
||||||
<div class="error-message">
|
<div class="error-message">
|
||||||
An error occurred while searching. Please try again later.
|
${error}. Please try again later.
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user