Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(qe): Ensure middleware for FindXOrThrow captures exceptions #16433

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions packages/client/tests/functional/query-error-logging/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,45 @@ testMatrix.setupTestSuite(
)
expect(errorEvent.target).toContain('user.findFirstOrThrow')
})

// Test for https://github.com/prisma/prisma/issues/16354
test('middleware captures errors', async () => {
prisma = newPrismaClient()
prisma.$use(async (params, next) => {
try {
return await next(params)
} catch (error) {
expect(params.action).toEqual('findFirstOrThrow')
throw new Error('Middleware error')
}
})

await expect(() =>
prisma.user.findFirstOrThrow({
where: {
email,
},
}),
).rejects.toThrowError('Middleware error')

prisma = newPrismaClient()
prisma.$use(async (params, next) => {
try {
return await next(params)
} catch (error) {
expect(params.action).toEqual('findUniqueOrThrow')
throw new Error('Middleware error')
}
})

await expect(() =>
prisma.user.findUniqueOrThrow({
where: {
email,
},
}),
).rejects.toThrowError('Middleware error')
})
},
{
skipDefaultClientInstance: true,
Expand Down