Skip to content

Commit

Permalink
Ensure errors from the hyper-ts app are caught correctly
Browse files Browse the repository at this point in the history
Refs #1834
  • Loading branch information
thewilkybarkid committed Sep 25, 2024
1 parent 3f41db0 commit ce2675a
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,36 +217,38 @@ export const app = (config: ConfigEnv) =>

next()
})
.use((req, res, next) => {
return pipe(
appMiddleware,
R.local((env: ConfigEnv): RouterEnv & LegacyEnv => ({
...env,
doesPreprintExist: withEnv(doesPreprintExist, env),
generateUuid: uuid.v4(),
getUser: withEnv(() => getUser, env),
getUserOnboarding: withEnv(getUserOnboarding, env),
getPreprint: withEnv(getPreprint, env),
getPreprintTitle: withEnv(getPreprintTitle, env),
templatePage: withEnv(page, env),
getPreprintIdFromUuid: withEnv(getPreprintIdFromLegacyPreviewUuid, env),
getProfileIdFromUuid: withEnv(getProfileIdFromLegacyPreviewUuid, env),
resolvePreprintId: withEnv(resolvePreprintId, env),
sendEmail: withEnv(sendEmail, env),
})),
R.local(
(appEnv: ConfigEnv): ConfigEnv => ({
...appEnv,
logger: pipe(
appEnv.logger,
l.contramap(entry => ({
...entry,
payload: { requestId: req.header('Fly-Request-Id') ?? null, ...entry.payload },
})),
),
}),
),
apply(config),
toRequestHandler,
)(req, res, next)
})
.use(
asyncHandler((req, res, next) => {
return pipe(
appMiddleware,
R.local((env: ConfigEnv): RouterEnv & LegacyEnv => ({
...env,
doesPreprintExist: withEnv(doesPreprintExist, env),
generateUuid: uuid.v4(),
getUser: withEnv(() => getUser, env),
getUserOnboarding: withEnv(getUserOnboarding, env),
getPreprint: withEnv(getPreprint, env),
getPreprintTitle: withEnv(getPreprintTitle, env),
templatePage: withEnv(page, env),
getPreprintIdFromUuid: withEnv(getPreprintIdFromLegacyPreviewUuid, env),
getProfileIdFromUuid: withEnv(getProfileIdFromLegacyPreviewUuid, env),
resolvePreprintId: withEnv(resolvePreprintId, env),
sendEmail: withEnv(sendEmail, env),
})),
R.local(
(appEnv: ConfigEnv): ConfigEnv => ({
...appEnv,
logger: pipe(
appEnv.logger,
l.contramap(entry => ({
...entry,
payload: { requestId: req.header('Fly-Request-Id') ?? null, ...entry.payload },
})),
),
}),
),
apply(config),
toRequestHandler,
)(req, res, next)
}),
)

0 comments on commit ce2675a

Please sign in to comment.