Skip to content

Commit 01c83c7

Browse files
committed
fix crashes due to null pointer
1 parent fd273ab commit 01c83c7

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

src/plugins/evlog.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ export const evlog = definePlugin<LoggerConfig>((app, options) => {
3333

3434
app.use(
3535
onError((error, event) => {
36-
event.context.logger.error(error)
36+
event.context.logger.set({ status: error.status })
37+
38+
if (error.status >= 500) {
39+
event.context.logger.error(error)
40+
}
41+
event.context.logger.emit()
3742
}),
3843
)
3944
})

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export const createErrorJson = (event: H3Event, input: HTTPError) => {
9999
message: input.message ?? "An error occurred.",
100100
}
101101

102-
if (input.status === 400 && "issues" in (input.data as ValiError<never>)) {
102+
if (input.status === 400 && "issues" in ((input?.data as ValiError<never>) ?? {})) {
103103
body.code = "FST_ERR_VALIDATION"
104104
body.message = "Validation error"
105105
body.details = flatten((input.data as ValiError<never>).issues)

0 commit comments

Comments
 (0)