Skip to content

Bug: falsy infer a http request when there is ok and Error in the return data strucutre  #362

@LatentDream

Description

@LatentDream

Describe the feature / bug 📝:

Bug using Error in the return data strucutre of a promise.
While there is no error raise, the toast take the error branch with the following message HTTP error! status: undefined

Steps to reproduce the bug 🔁:

promise data structure return

export type Result<T, E = Error> =
  | { ok: true; value: T }
  | { ok: false; error: E };

export function Ok<T, E>(value: T): Result<T, E> {
  return { ok: true, value };
}
export function Err<T, E>(error: E): Result<T, E> {
  return { ok: false, error };
}

Code to reproduce the bug

async function whatWillHappen(): Promise<Result<null, Error>> {
  return Err(new Error("Not implemented"));
}

export function useSaveProject() {
  const handle = async () => {
    toast.promise(whatWillHappen, {
    loading: "Saving project...",
    success: (result) => {
      if (result.ok) {
        return "Project saved";
      } else {
        return `Result Error: ${result.error}`;
      }
    },
    error: (e) => `Error Raise: ${e}`,
    });
  };

  return (handle);
}

This return:
Error Raise: HTTP error! status: undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions