From d95ca43e0fbf0679ec1ed06c934fa1a9a42a8e02 Mon Sep 17 00:00:00 2001 From: nom3ad <19239479+nom3ad@users.noreply.github.com> Date: Tue, 12 Oct 2021 11:16:30 +0530 Subject: [PATCH] fix(cognito): proper error message when same trigger is added twice --- packages/@aws-cdk/aws-cognito/lib/user-pool.ts | 2 +- packages/@aws-cdk/aws-cognito/test/user-pool.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-cognito/lib/user-pool.ts b/packages/@aws-cdk/aws-cognito/lib/user-pool.ts index 6277ee0f467ee..adc3f51bf37a2 100644 --- a/packages/@aws-cdk/aws-cognito/lib/user-pool.ts +++ b/packages/@aws-cdk/aws-cognito/lib/user-pool.ts @@ -830,7 +830,7 @@ export class UserPool extends UserPoolBase { */ public addTrigger(operation: UserPoolOperation, fn: lambda.IFunction): void { if (operation.operationName in this.triggers) { - throw new Error(`A trigger for the operation ${operation} already exists.`); + throw new Error(`A trigger for the operation ${operation.operationName} already exists.`); } this.addLambdaPermission(fn, operation.operationName); diff --git a/packages/@aws-cdk/aws-cognito/test/user-pool.test.ts b/packages/@aws-cdk/aws-cognito/test/user-pool.test.ts index 7b132803da2d6..5aa6c48ee99fc 100644 --- a/packages/@aws-cdk/aws-cognito/test/user-pool.test.ts +++ b/packages/@aws-cdk/aws-cognito/test/user-pool.test.ts @@ -403,7 +403,7 @@ describe('User Pool', () => { // WHEN userpool.addTrigger(UserPoolOperation.CREATE_AUTH_CHALLENGE, fn1); - expect(() => userpool.addTrigger(UserPoolOperation.CREATE_AUTH_CHALLENGE, fn2)).toThrow(/already exists/); + expect(() => userpool.addTrigger(UserPoolOperation.CREATE_AUTH_CHALLENGE, fn2)).toThrow(/createAuthChallenge already exists/); }); test('no username aliases specified', () => {