Skip to content

Add error handling for location fetching #93

Description

@raven-wing
          _:warning: Potential issue_

Add error handling for location fetching

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

+    const [isLoading, setIsLoading] = useState(false);
+    const [error, setError] = useState(null);

     useEffect(() => {
+        const abortController = new AbortController();
+        setIsLoading(true);
         httpService
-            .getLocationsWithLatLon(userPosition.lat, userPosition.lng, categories)
+            .getLocationsWithLatLon(userPosition.lat, userPosition.lng, categories, abortController.signal)
             .then(places => {
                 setData(places);
+            })
+            .catch(error => {
+                if (!error.name === 'AbortError') {
+                    setError(error);
+                    console.error('Failed to fetch locations:', error);
+                }
+            })
+            .finally(() => {
+                setIsLoading(false);
             });
+        return () => abortController.abort();
     }, [categories, userPosition]);

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

🧰 Tools
🪛 eslint

[error] 28-28: Expected parentheses around arrow function argument.

(arrow-parens)

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