@@ -5,6 +5,7 @@ import { CfnEventSourceMapping } from './lambda.generated';
5
5
import * as iam from '../../aws-iam' ;
6
6
import { IKey } from '../../aws-kms' ;
7
7
import * as cdk from '../../core' ;
8
+ import { ValidationError } from '../../core/lib/errors' ;
8
9
9
10
/**
10
11
* The type of authentication protocol or the VPC components for your event source's SourceAccessConfiguration
@@ -402,78 +403,78 @@ export class EventSourceMapping extends cdk.Resource implements IEventSourceMapp
402
403
super ( scope , id ) ;
403
404
404
405
if ( props . eventSourceArn == undefined && props . kafkaBootstrapServers == undefined ) {
405
- throw new Error ( 'Either eventSourceArn or kafkaBootstrapServers must be set' ) ;
406
+ throw new ValidationError ( 'Either eventSourceArn or kafkaBootstrapServers must be set' , this ) ;
406
407
}
407
408
408
409
if ( props . eventSourceArn !== undefined && props . kafkaBootstrapServers !== undefined ) {
409
- throw new Error ( 'eventSourceArn and kafkaBootstrapServers are mutually exclusive' ) ;
410
+ throw new ValidationError ( 'eventSourceArn and kafkaBootstrapServers are mutually exclusive' , this ) ;
410
411
}
411
412
412
413
if ( props . provisionedPollerConfig ) {
413
414
const { minimumPollers, maximumPollers } = props . provisionedPollerConfig ;
414
415
if ( minimumPollers != undefined ) {
415
416
if ( minimumPollers < 1 || minimumPollers > 200 ) {
416
- throw new Error ( 'Minimum provisioned pollers must be between 1 and 200 inclusive' ) ;
417
+ throw new ValidationError ( 'Minimum provisioned pollers must be between 1 and 200 inclusive' , this ) ;
417
418
}
418
419
}
419
420
if ( maximumPollers != undefined ) {
420
421
if ( maximumPollers < 1 || maximumPollers > 2000 ) {
421
- throw new Error ( 'Maximum provisioned pollers must be between 1 and 2000 inclusive' ) ;
422
+ throw new ValidationError ( 'Maximum provisioned pollers must be between 1 and 2000 inclusive' , this ) ;
422
423
}
423
424
}
424
425
if ( minimumPollers != undefined && maximumPollers != undefined ) {
425
426
if ( minimumPollers > maximumPollers ) {
426
- throw new Error ( 'Minimum provisioned pollers must be less than or equal to maximum provisioned pollers' ) ;
427
+ throw new ValidationError ( 'Minimum provisioned pollers must be less than or equal to maximum provisioned pollers' , this ) ;
427
428
}
428
429
}
429
430
}
430
431
431
432
if ( props . kafkaBootstrapServers && ( props . kafkaBootstrapServers ?. length < 1 ) ) {
432
- throw new Error ( 'kafkaBootStrapServers must not be empty if set' ) ;
433
+ throw new ValidationError ( 'kafkaBootStrapServers must not be empty if set' , this ) ;
433
434
}
434
435
435
436
if ( props . maxBatchingWindow && props . maxBatchingWindow . toSeconds ( ) > 300 ) {
436
- throw new Error ( `maxBatchingWindow cannot be over 300 seconds, got ${ props . maxBatchingWindow . toSeconds ( ) } ` ) ;
437
+ throw new ValidationError ( `maxBatchingWindow cannot be over 300 seconds, got ${ props . maxBatchingWindow . toSeconds ( ) } ` , this ) ;
437
438
}
438
439
439
440
if ( props . maxConcurrency && ! cdk . Token . isUnresolved ( props . maxConcurrency ) && ( props . maxConcurrency < 2 || props . maxConcurrency > 1000 ) ) {
440
- throw new Error ( 'maxConcurrency must be between 2 and 1000 concurrent instances' ) ;
441
+ throw new ValidationError ( 'maxConcurrency must be between 2 and 1000 concurrent instances' , this ) ;
441
442
}
442
443
443
444
if ( props . maxRecordAge && ( props . maxRecordAge . toSeconds ( ) < 60 || props . maxRecordAge . toDays ( { integral : false } ) > 7 ) ) {
444
- throw new Error ( 'maxRecordAge must be between 60 seconds and 7 days inclusive' ) ;
445
+ throw new ValidationError ( 'maxRecordAge must be between 60 seconds and 7 days inclusive' , this ) ;
445
446
}
446
447
447
448
props . retryAttempts !== undefined && cdk . withResolved ( props . retryAttempts , ( attempts ) => {
448
449
if ( attempts < 0 || attempts > 10000 ) {
449
- throw new Error ( `retryAttempts must be between 0 and 10000 inclusive, got ${ attempts } ` ) ;
450
+ throw new ValidationError ( `retryAttempts must be between 0 and 10000 inclusive, got ${ attempts } ` , this ) ;
450
451
}
451
452
} ) ;
452
453
453
454
props . parallelizationFactor !== undefined && cdk . withResolved ( props . parallelizationFactor , ( factor ) => {
454
455
if ( factor < 1 || factor > 10 ) {
455
- throw new Error ( `parallelizationFactor must be between 1 and 10 inclusive, got ${ factor } ` ) ;
456
+ throw new ValidationError ( `parallelizationFactor must be between 1 and 10 inclusive, got ${ factor } ` , this ) ;
456
457
}
457
458
} ) ;
458
459
459
460
if ( props . tumblingWindow && ! cdk . Token . isUnresolved ( props . tumblingWindow ) && props . tumblingWindow . toSeconds ( ) > 900 ) {
460
- throw new Error ( `tumblingWindow cannot be over 900 seconds, got ${ props . tumblingWindow . toSeconds ( ) } ` ) ;
461
+ throw new ValidationError ( `tumblingWindow cannot be over 900 seconds, got ${ props . tumblingWindow . toSeconds ( ) } ` , this ) ;
461
462
}
462
463
463
464
if ( props . startingPosition === StartingPosition . AT_TIMESTAMP && ! props . startingPositionTimestamp ) {
464
- throw new Error ( 'startingPositionTimestamp must be provided when startingPosition is AT_TIMESTAMP' ) ;
465
+ throw new ValidationError ( 'startingPositionTimestamp must be provided when startingPosition is AT_TIMESTAMP' , this ) ;
465
466
}
466
467
467
468
if ( props . startingPosition !== StartingPosition . AT_TIMESTAMP && props . startingPositionTimestamp ) {
468
- throw new Error ( 'startingPositionTimestamp can only be used when startingPosition is AT_TIMESTAMP' ) ;
469
+ throw new ValidationError ( 'startingPositionTimestamp can only be used when startingPosition is AT_TIMESTAMP' , this ) ;
469
470
}
470
471
471
472
if ( props . kafkaConsumerGroupId ) {
472
473
this . validateKafkaConsumerGroupIdOrThrow ( props . kafkaConsumerGroupId ) ;
473
474
}
474
475
475
476
if ( props . filterEncryption !== undefined && props . filters == undefined ) {
476
- throw new Error ( 'filter criteria must be provided to enable setting filter criteria encryption' ) ;
477
+ throw new ValidationError ( 'filter criteria must be provided to enable setting filter criteria encryption' , this ) ;
477
478
}
478
479
479
480
/**
@@ -540,13 +541,13 @@ export class EventSourceMapping extends cdk.Resource implements IEventSourceMapp
540
541
}
541
542
542
543
if ( kafkaConsumerGroupId . length > 200 || kafkaConsumerGroupId . length < 1 ) {
543
- throw new Error ( 'kafkaConsumerGroupId must be a valid string between 1 and 200 characters' ) ;
544
+ throw new ValidationError ( 'kafkaConsumerGroupId must be a valid string between 1 and 200 characters' , this ) ;
544
545
}
545
546
546
547
const regex = new RegExp ( / [ a - z A - Z 0 - 9 -\/ * : _ + = . @ - ] * / ) ;
547
548
const patternMatch = regex . exec ( kafkaConsumerGroupId ) ;
548
549
if ( patternMatch === null || patternMatch [ 0 ] !== kafkaConsumerGroupId ) {
549
- throw new Error ( 'kafkaConsumerGroupId contains invalid characters. Allowed values are "[a-zA-Z0-9-\/*:_+=.@-]"' ) ;
550
+ throw new ValidationError ( 'kafkaConsumerGroupId contains invalid characters. Allowed values are "[a-zA-Z0-9-\/*:_+=.@-]"' , this ) ;
550
551
}
551
552
}
552
553
}
0 commit comments