Skip to content

Commit

Permalink
Make error matching exhaustive
Browse files Browse the repository at this point in the history
Refs #388
  • Loading branch information
thewilkybarkid committed Oct 24, 2022
1 parent cd8d4d3 commit f0e81a1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/write-review/write-review-add-author.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const writeReviewAddAuthor = flow(
),
RM.filterOrElseW(
({ canAddAuthors }) => canAddAuthors,
() => 'not-found',
() => 'not-found' as const,
),
RM.bindW(
'form',
Expand All @@ -53,8 +53,12 @@ export const writeReviewAddAuthor = flow(
),
RM.orElseW(error =>
match(error)
.with(
'no-session',
fromMiddlewareK(() => seeOther(format(writeReviewMatch.formatter, { doi: preprint.doi }))),
)
.with('not-found', () => notFound)
.otherwise(fromMiddlewareK(() => seeOther(format(writeReviewMatch.formatter, { doi: preprint.doi })))),
.exhaustive(),
),
),
),
Expand Down
10 changes: 7 additions & 3 deletions src/write-review/write-review-change-author.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export const writeReviewChangeAuthor = (doi: PreprintId['doi'], index: number) =
),
RM.filterOrElseW(
({ canAddAuthors }) => canAddAuthors,
() => 'not-found',
() => 'not-found' as const,
),
RM.bindW(
'form',
RM.fromReaderTaskK(({ user }) => getForm(user.orcid, preprint.doi)),
),
RM.bindW(
'author',
fromOptionK(() => 'not-found')(
fromOptionK(() => 'not-found' as const)(
flow(
O.fromNullableK(({ form }) => form.otherAuthors),
O.chain(RA.lookup(index)),
Expand All @@ -61,8 +61,12 @@ export const writeReviewChangeAuthor = (doi: PreprintId['doi'], index: number) =
),
RM.orElseW(error =>
match(error)
.with(
'no-session',
fromMiddlewareK(() => seeOther(format(writeReviewMatch.formatter, { doi: preprint.doi }))),
)
.with('not-found', () => notFound)
.otherwise(fromMiddlewareK(() => seeOther(format(writeReviewMatch.formatter, { doi: preprint.doi })))),
.exhaustive(),
),
),
),
Expand Down
10 changes: 7 additions & 3 deletions src/write-review/write-review-remove-author.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ export const writeReviewRemoveAuthor = (doi: PreprintId['doi'], index: number) =
),
RM.filterOrElseW(
({ canAddAuthors }) => canAddAuthors,
() => 'not-found',
() => 'not-found' as const,
),
RM.bindW(
'form',
RM.fromReaderTaskK(({ user }) => getForm(user.orcid, preprint.doi)),
),
RM.bindW(
'author',
fromOptionK(() => 'not-found')(
fromOptionK(() => 'not-found' as const)(
flow(
O.fromNullableK(({ form }) => form.otherAuthors),
O.chain(RA.lookup(index)),
Expand All @@ -65,8 +65,12 @@ export const writeReviewRemoveAuthor = (doi: PreprintId['doi'], index: number) =
),
RM.orElseW(error =>
match(error)
.with(
'no-session',
fromMiddlewareK(() => seeOther(format(writeReviewMatch.formatter, { doi: preprint.doi }))),
)
.with('not-found', () => notFound)
.otherwise(fromMiddlewareK(() => seeOther(format(writeReviewMatch.formatter, { doi: preprint.doi })))),
.exhaustive(),
),
),
),
Expand Down

0 comments on commit f0e81a1

Please sign in to comment.