Skip to content

Add error handling for category fetching #91

Description

@raven-wing
          _:warning: Potential issue_

Add error handling for category fetching

The category fetching logic lacks error handling and loading state management.

 useEffect(() => {
+    const abortController = new AbortController();
+    setIsLoading(true);
     const fetchCategories = async () => {
         try {
-            const categoriesData = await httpService.getCategoriesData();
+            const fetchedCategoriesData = await httpService.getCategoriesData(abortController.signal);
             setCategoriesData(categoriesData);
+        } catch (error) {
+            if (!error.name === 'AbortError') {
+                setError(error);
+                console.error('Failed to fetch categories:', error);
+            }
+        } finally {
+            setIsLoading(false);
         }
     };
     fetchCategories();
+    return () => abortController.abort();
 }, []);

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 eslint

[error] 42-45: ES2017 async function declarations are forbidden.

(es-x/no-async-functions)


[error] 43-43: 'categoriesData' is already declared in the upper scope on line 9 column 12.

(no-shadow)

Originally posted by @coderabbitai[bot] in #90 (comment)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions