Skip to content

useSonarEntity returns no error when entity is not found #21

Description

@fpv-dev

I don't know why, but it seems useSonarEntity intentionally treats 404 as no-error, which a little bit confusing, especially, there is no any notes in documentation about that edge case.

  const refetch = useCallback2(async () => {
    if (!walletAddress || !fullyConnected) {
      return;
    }
    setState((s) => ({ ...s, loading: true }));
    try {
      const resp = await client.readEntity({
        saleUUID,
        walletAddress
      });
      setState({
        loading: false,
        entity: resp.Entity,
        walletAddress,
        error: void 0,
        hasFetched: true
      });
    } catch (err) {
      if (err instanceof APIError && err.status === 404) {
        setState({
          loading: false,
          entity: void 0,
          walletAddress: void 0,
          error: void 0,
          hasFetched: true
        });
        return;
      }
      const error = err instanceof Error ? err : new Error(String(err));
      setState({ loading: false, entity: void 0, walletAddress: void 0, error, hasFetched: true });
    }
  }, [client, saleUUID, walletAddress, fullyConnected]);

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