From 78520ad8b6677db403fcdac8369ee8b29f9b6d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vi=CC=81tor=20Galva=CC=83o?= Date: Wed, 6 Mar 2024 17:39:54 +0000 Subject: [PATCH] On error, show timestamp and delete cache files --- Workflow/chatgpt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Workflow/chatgpt b/Workflow/chatgpt index cd5b24d..47a9688 100755 --- a/Workflow/chatgpt +++ b/Workflow/chatgpt @@ -101,10 +101,16 @@ function readStream(streamFile, chatFile, pidStreamFile) { try { const errorMessage = JSON.parse(streamString)["error"]["message"] - if (errorMessage) return JSON.stringify({ - response: `[${errorMessage}]`, // Surround in square brackets to look like other messages - behaviour: { response: "replacelast" } - }) + if (errorMessage) { + // Delete stream files + deleteFile(streamFile) + deleteFile(pidStreamFile) + + return JSON.stringify({ + response: `[${errorMessage}] \n(${(new Date).toUTCString()})`, // Surround in square brackets to look like other messages + behaviour: { response: "replacelast" } + }) + } throw "Could not determine error message" // Fallback to the catch } catch {