Handling Errors in Hono Handler with Effect and Match
Hello, is there a better or more idiomatic way to handle errors (it's inside a Hono handler)? My goal is for the pattern matching to be exhaustive.
return Effect.gen(function* () {
const { orgaId } = c.req.param()
const orgaService = yield* OrgaService
return yield* orgaService.getOrga(orgaId)
}).pipe(
Effect.match({
onSuccess: (result) => c.json(result),
onFailure: (error) =>
Match.value(error).pipe(
Match.tag("NoSuchElementException", () => c.notFound()),
Match.exhaustive
),
}),
Effect.provide(OrgaService.Default),
Effect.runPromise
)