Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where does tryCatch / external deps come from? #14

Open
SlexAxton opened this issue Jan 23, 2025 · 2 comments
Open

Where does tryCatch / external deps come from? #14

SlexAxton opened this issue Jan 23, 2025 · 2 comments

Comments

@SlexAxton
Copy link

I'm used to it from fp-ts but the function signature here is slightly different. I also hadn't been aware of waitUntil from @vercel/functions - perhaps we could add in which external dependencies are being relied on here, just to save people some mental overhead?

@zbeyens
Copy link

zbeyens commented Jan 25, 2025

I'm using this for tryCatch:

/** Attempts to execute a promise and returns an object with the result or error. */
export async function tryCatch<T>(promise: Promise<T>): Promise<{
  data?: T;
  error?: Error;
}> {
  try {
    const data = await promise;

    return { data };
  } catch (error) {
    if (error instanceof Error) {
      return { error };
    }

    // Handle non-Error throws by wrapping them
    return { error: new Error(String(error)) };
  }
}

@joeytitanium
Copy link

he actually just posted the code on 𝕏

https://gist.github.com/t3dotgg/a486c4ae66d32bf17c09c73609dacc5b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants