From 53745146593ba20ea1de061101f2731e4c98741c Mon Sep 17 00:00:00 2001 From: Kesara Rathnayake Date: Tue, 4 Feb 2025 16:36:29 +1300 Subject: [PATCH] fix: Handle ABNF API errors (#573) --- static/scripts/abnf.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/static/scripts/abnf.js b/static/scripts/abnf.js index dfc447b..0b99340 100644 --- a/static/scripts/abnf.js +++ b/static/scripts/abnf.js @@ -84,7 +84,12 @@ function parse() { }); fetch(request) - .then(function(response) { return response.json(); }) + .then(function(response) { + if (!response.ok) { + throw new Error(`There was an issue processing your request. (HTTP Status: ${response.status})`); + } + return response.json(); + }) .then(function(json) { reset(); if (json.errors) { @@ -96,5 +101,10 @@ function parse() { preAbnf.textContent = json.abnf; } accordionAbnfParse.scrollIntoView(); + }) + .catch(error => { + accordionItemErrors.style.display = 'block'; + preErrors.textContent = error; + resetButtons(); }); }