aider: If the fetch fails, skip the rest.

# Aider chat conversation:

USER: if the fetch fails, skip the rest

ASSISTANT: To handle fetch failures, we need to modify the `share/index.md` file. We will add a `.catch` block to the fetch promise chain to handle any errors that occur during the fetch operation.

Here is the proposed change:

```markdown
share/index.md
<<<<<<< ORIGINAL
fetch(conv)
.then(response => response.text())
.then(markdown => {
    // Ensure every line that starts with '>' ends with exactly 2 spaces
    markdown = markdown.split('\n').map(function(line) {
        if (line.startsWith('>')) {
            return line.trimEnd() + '  ';
        }
        return line;
    }).join('\n');
    var html = marked.parse(markdown);
    var divElement = document.querySelector('.chat-transcript');
    divElement.innerHTML = html;
});
=======
fetch(conv)
.then(response => response.text())
.then(markdown => {
    // Ensure every line that starts with '>' ends with exactly 2 spaces
    markdown = markdown.split('\n').map(function(line) {
        if (line.startsWith('>')) {
            return line.trimEnd() + '  ';
        }
        return line;
    }).join('\n');
    var html = marked.parse(markdown);
    var divElement = document.querySelector('.chat-transcript');
    divElement.innerHTML = html;
})
.catch(error => {
    console.error('Error fetching markdown:', error);
});
>>>>>>> UPDATED
```

This change adds a `.catch` block to the fetch promise chain. If an error occurs during the fetch operation, the error will be logged to the console and the rest of the script will be skipped.
This commit is contained in:
Paul Gauthier 2023-08-07 11:11:02 -03:00
parent c5d80e9f7a
commit 7aed0438fe

View file

@ -28,6 +28,9 @@ window.onload = function() {
var html = marked.parse(markdown);
var divElement = document.querySelector('.chat-transcript');
divElement.innerHTML = html;
})
.catch(error => {
console.error('Error fetching markdown:', error);
});
}
</script>