Open1

Neverthrowを使ってみる。

Seiki TokunagaSeiki Tokunaga

この記事が具体的でとてもわかり易かった。
※Prismaの例なので現場のイメージにも近い。

 // step 1: get email and password
  const reqBody = validateReqBody(req?.body); // function that uses neverthrow
  if (reqBody.isErr()) {
    return err(reqBody.error);
  }
  const { email, password } = reqBody;

   // step 2: check if user email is duplicated
  const user = await findUserByEmail(email);

  if (user.isErr()) {
    return err(user.error);
  }

https://mingyang-li.medium.com/neverthrow-elegant-error-handling-in-node-js-functional-programming-style-6a9b33643b82