From 7aed0438fefc68b3e10465d106564b204f3372e6 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 7 Aug 2023 11:11:02 -0300 Subject: [PATCH] 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. --- share/index.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/share/index.md b/share/index.md index 4935e5296..03784289c 100644 --- a/share/index.md +++ b/share/index.md @@ -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); }); }