From aa2002f5d496961dcc5751afb8ba91bc2694913d Mon Sep 17 00:00:00 2001 From: Alan Rocha Date: Thu, 7 Nov 2024 20:40:16 -0300 Subject: [PATCH] feat(search-form): implement basic error handling --- src/components/search-form.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/search-form.tsx b/src/components/search-form.tsx index 203c103..b331eef 100644 --- a/src/components/search-form.tsx +++ b/src/components/search-form.tsx @@ -19,8 +19,13 @@ export default function SearchForm(props: SearchFormProps) { body: formData, }); - const data: SearchResult[] = await response.json(); - props.onSearchResultsReady(data); + if (response.status === 200) { + const data: SearchResult[] = await response.json(); + props.onSearchResultsReady(data); + } else { + // TODO: Implement toastify to show a beautiful error message + alert("Ocorreu um erro na busca. Tente novamente mais tarde."); + } setIsLoading(false); }