From f120438504422befe3b92d8b75317832c720356c Mon Sep 17 00:00:00 2001 From: Miguel Fernandez Date: Fri, 25 Nov 2022 13:04:17 +0100 Subject: [PATCH] Ensure #16354 is fixed --- .../functional/query-error-logging/tests.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/packages/client/tests/functional/query-error-logging/tests.ts b/packages/client/tests/functional/query-error-logging/tests.ts index db727d23111e..df6aeadbd7d0 100644 --- a/packages/client/tests/functional/query-error-logging/tests.ts +++ b/packages/client/tests/functional/query-error-logging/tests.ts @@ -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,