Skip to content

Add error state handling in general settings manager #911

@MODSetter

Description

@MODSetter

Description

The general settings manager doesn't handle query errors. If fetching the search space fails, the form renders with empty fields and no indication that something went wrong.

Files to Update

  • surfsense_web/components/settings/general-settings-manager.tsx (lines 26–34)

What to Do

  1. Destructure isError from the useQuery call:
const {
  data: searchSpace,
  isLoading: loading,
  isError,
  refetch: fetchSearchSpace,
} = useQuery({
  queryKey: cacheKeys.searchSpaces.detail(searchSpaceId.toString()),
  queryFn: () => searchSpacesApiService.getSearchSpace({ id: searchSpaceId }),
  enabled: !!searchSpaceId,
});
  1. Add an error state check after the loading check (before the form renders):
if (isError) {
  return (
    <div className="flex flex-col items-center justify-center gap-3 py-8 text-center">
      <p className="text-sm text-destructive">Failed to load settings.</p>
      <Button variant="outline" size="sm" onClick={() => fetchSearchSpace()}>
        Retry
      </Button>
    </div>
  );
}

This gives users clear feedback and a way to recover instead of showing a broken empty form.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions