From e92cee312965077e9a01fadd1bde3116fbcb72eb Mon Sep 17 00:00:00 2001 From: wonderlandpark Date: Sun, 9 May 2021 13:42:20 +0900 Subject: [PATCH] fix: handle AbortError --- components/Search.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/Search.tsx b/components/Search.tsx index 9f31168..4148ac2 100644 --- a/components/Search.tsx +++ b/components/Search.tsx @@ -35,7 +35,7 @@ const Search = (): JSX.Element => { setQuery(value) try { abortControl.abort() - } catch { + } catch (e) { return null } const controller = new AbortController() @@ -43,8 +43,11 @@ const Search = (): JSX.Element => { if (value.length > 1) setLoading(true) const res = await Fetch(`/search/bots?q=${encodeURIComponent(value)}`, { signal: controller.signal, + }).catch((e) => { + if(e.name !== 'AbortError') throw e + else return }) - setData(res) + setData(res || {}) setLoading(false) }