Handling unknown errors from an external API by wrapping them in the `cause` of a `TaggedError` i...

For unknown errors from an external api, is the good practice to wrap it in the "cause" of a TaggedError ?
I should define all my tagged errors as having a cause and always put the unknown error in it by default?

Example:

export class DatabaseError extends TaggedError("DatabaseError")<{
  cause: unknown;
}> {}


export const myFun = <A>(fn: () => Promise<A>): E.Effect<A, DatabaseError> =>
  E.tryPromise({
    try: fn,
    catch: (e) => new DatabaseError({ cause: e }),
  });
Was this page helpful?