Skip to content

Commit

Permalink
chore: split the nested ternaries in Either.extended.ts into two func…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
PenghaiZhang committed Sep 28, 2023
1 parent 2bca408 commit 41b470e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions react-front-end/tsrc/util/Either.extended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ const buildErrorFromValidation: (e: Errors) => Error = flow(
(error) => new Error(error)
);

const buildErrorFromString = (e: string | Errors): Error =>
typeof e === "string" ? new Error(e) : buildErrorFromValidation(e);

const buildError = (e: string | Error | Errors): Error =>
e instanceof Error
? e
: typeof e === "string"
? new Error(e)
: buildErrorFromValidation(e);
e instanceof Error ? e : buildErrorFromString(e);

/**
* Given an Either, return the value or throw an error.
Expand Down

0 comments on commit 41b470e

Please sign in to comment.