Skip to content

Commit

Permalink
Ensure #16354 is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelff committed Nov 24, 2022
1 parent ef408ae commit b60006f
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/client/tests/functional/query-error-logging/tests.ts
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

0 comments on commit b60006f

Please sign in to comment.