From 060ac4f41ea3f7c0524a0bd71f58749cd40c7970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Sverre=20Lien=20Sell=C3=A6g?= Date: Wed, 3 Jun 2020 14:20:47 +0200 Subject: [PATCH] handle errors from server --- src/Events.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Events.js b/src/Events.js index 2add980..c010efa 100644 --- a/src/Events.js +++ b/src/Events.js @@ -115,9 +115,14 @@ export default function Events() { useEffect(async () => { if (events === null) { - const res = await fetch(endpoint, fetch_options) - const result = await res.json() - setEvents(events) + let result = [] + try { + const res = await fetch(endpoint, fetch_options) + result = await res.json() + } catch (error) { + console.error(error) + } + setEvents(result) } }, [events])