From 1b022c5077ac0366bbd9b5581689d24de5dad4e9 Mon Sep 17 00:00:00 2001 From: Edy Segura Date: Mon, 13 Jan 2025 23:05:07 -0300 Subject: [PATCH] chore: baseline for handling fetch exception for 4xx and 5xx --- handling-fetch/app.js | 12 ++++++++++++ handling-fetch/index.html | 0 2 files changed, 12 insertions(+) create mode 100644 handling-fetch/app.js create mode 100644 handling-fetch/index.html diff --git a/handling-fetch/app.js b/handling-fetch/app.js new file mode 100644 index 0000000..c499e96 --- /dev/null +++ b/handling-fetch/app.js @@ -0,0 +1,12 @@ +async function doRequest() { + let response + try { + response = await fetch('https://httpstat.us/400') + if (response.ok) { + return response + } + throw new Error(`Error: Response status ${response.status}`) + } catch (error) { + return error + } +} diff --git a/handling-fetch/index.html b/handling-fetch/index.html new file mode 100644 index 0000000..e69de29