From 5d12996aec968ce55652be27a96e0c0456ae5979 Mon Sep 17 00:00:00 2001 From: nune <145225213+gigirassy@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:47:55 -0500 Subject: [PATCH] Update client.js --- public/client.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/public/client.js b/public/client.js index 152f0fa..604c97b 100644 --- a/public/client.js +++ b/public/client.js @@ -5,12 +5,13 @@ document.getElementById('fetchBtn').addEventListener('click', async () => { try { const response = await fetch(`/fetch-paste?url=${encodeURIComponent(urlInput)}`); - const data = await response.json(); - if (data.error) { - output.textContent = `Error: ${data.error}`; - } else { - output.textContent = data.text; + if (!response.ok) { + const errorData = await response.json(); // Parse error JSON + throw new Error(errorData.error || 'Unknown error occurred'); } + + const data = await response.json(); + output.textContent = data.text; } catch (error) { output.textContent = `Error: ${error.message}`; }