Skip to content

Commit

Permalink
Prefer Effect's matcher
Browse files Browse the repository at this point in the history
Refs #1834
  • Loading branch information
thewilkybarkid committed Dec 13, 2024
1 parent 6308287 commit c4470c2
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/ghost.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { FetchHttpClient, HttpClient, HttpClientResponse } from '@effect/platform'
import { Context, Effect, identity, Schema } from 'effect'
import { Context, Effect, flow, identity, Match, Schema } from 'effect'
import type * as F from 'fetch-fp-ts'
import * as E from 'fp-ts/lib/Either.js'
import * as R from 'fp-ts/lib/Reader.js'
import * as RTE from 'fp-ts/lib/ReaderTaskEither.js'
import { pipe } from 'fp-ts/lib/function.js'
import { Status } from 'hyper-ts'
import { match } from 'ts-pattern'
import { StatusCodes } from 'http-status-codes'
import { URL } from 'url'
import { type SleepEnv, revalidateIfStale, useStaleCache } from './fetch.js'
import { type Html, rawHtml, sanitizeHtml } from './html.js'
Expand Down Expand Up @@ -71,10 +70,12 @@ const getPageWithEffect = (id: string) =>
Effect.andThen(html =>
rawHtml(html.toString().replaceAll(/href="https?:\/\/prereview\.org\/?(.*?)"/g, 'href="/$1"')),
),
Effect.mapError(error =>
match(error)
.with({ status: Status.NotFound }, () => 'not-found' as const)
.otherwise(() => 'unavailable' as const),
Effect.mapError(
flow(
Match.value,
Match.when({ status: StatusCodes.NOT_FOUND }, () => 'not-found' as const),
Match.orElse(() => 'unavailable' as const),
),
),
)
})

0 comments on commit c4470c2

Please sign in to comment.