@@ -5,6 +5,7 @@ import { validateProps } from './validate-props';
5
5
import * as iam from '../../aws-iam' ;
6
6
import * as kms from '../../aws-kms' ;
7
7
import { Duration , RemovalPolicy , Stack , Token , ArnFormat , Annotations } from '../../core' ;
8
+ import { ValidationError } from '../../core/lib/errors' ;
8
9
9
10
/**
10
11
* Properties for creating a new Queue
@@ -325,10 +326,10 @@ export class Queue extends QueueBase {
325
326
} else {
326
327
if ( typeof attrs . fifo !== 'undefined' ) {
327
328
if ( attrs . fifo && ! queueName . endsWith ( '.fifo' ) ) {
328
- throw new Error ( "FIFO queue names must end in '.fifo'" ) ;
329
+ throw new ValidationError ( "FIFO queue names must end in '.fifo'" , this ) ;
329
330
}
330
331
if ( ! attrs . fifo && queueName . endsWith ( '.fifo' ) ) {
331
- throw new Error ( "Non-FIFO queue name may not end in '.fifo'" ) ;
332
+ throw new ValidationError ( "Non-FIFO queue name may not end in '.fifo'" , this ) ;
332
333
}
333
334
}
334
335
return queueName . endsWith ( '.fifo' ) ? true : false ;
@@ -383,19 +384,19 @@ export class Queue extends QueueBase {
383
384
physicalName : props . queueName ,
384
385
} ) ;
385
386
386
- validateProps ( props ) ;
387
+ validateProps ( this , props ) ;
387
388
388
389
if ( props . redriveAllowPolicy ) {
389
390
const { redrivePermission, sourceQueues } = props . redriveAllowPolicy ;
390
391
if ( redrivePermission === RedrivePermission . BY_QUEUE ) {
391
392
if ( ! sourceQueues || sourceQueues . length === 0 ) {
392
- throw new Error ( 'At least one source queue must be specified when RedrivePermission is set to \'byQueue\'' ) ;
393
+ throw new ValidationError ( 'At least one source queue must be specified when RedrivePermission is set to \'byQueue\'' , this ) ;
393
394
}
394
395
if ( sourceQueues && sourceQueues . length > 10 ) {
395
- throw new Error ( 'Up to 10 sourceQueues can be specified. Set RedrivePermission to \'allowAll\' to specify more' ) ;
396
+ throw new ValidationError ( 'Up to 10 sourceQueues can be specified. Set RedrivePermission to \'allowAll\' to specify more' , this ) ;
396
397
}
397
398
} else if ( redrivePermission && sourceQueues ) {
398
- throw new Error ( 'sourceQueues cannot be configured when RedrivePermission is set to \'allowAll\' or \'denyAll\'' ) ;
399
+ throw new ValidationError ( 'sourceQueues cannot be configured when RedrivePermission is set to \'allowAll\' or \'denyAll\'' , this ) ;
399
400
}
400
401
}
401
402
@@ -452,7 +453,7 @@ export class Queue extends QueueBase {
452
453
let encryption = props . encryption ;
453
454
454
455
if ( encryption === QueueEncryption . SQS_MANAGED && props . encryptionMasterKey ) {
455
- throw new Error ( "'encryptionMasterKey' is not supported if encryption type 'SQS_MANAGED' is used" ) ;
456
+ throw new ValidationError ( "'encryptionMasterKey' is not supported if encryption type 'SQS_MANAGED' is used" , this ) ;
456
457
}
457
458
458
459
if ( encryption !== QueueEncryption . KMS && props . encryptionMasterKey ) {
@@ -513,7 +514,7 @@ export class Queue extends QueueBase {
513
514
} ;
514
515
}
515
516
516
- throw new Error ( `Unexpected 'encryptionType': ${ encryption } ` ) ;
517
+ throw new ValidationError ( `Unexpected 'encryptionType': ${ encryption } ` , this ) ;
517
518
}
518
519
519
520
// Enforce encryption of data in transit
@@ -537,23 +538,23 @@ export class Queue extends QueueBase {
537
538
// If we have a name, see that it agrees with the FIFO setting
538
539
if ( typeof queueName === 'string' ) {
539
540
if ( fifoQueue && ! queueName . endsWith ( '.fifo' ) ) {
540
- throw new Error ( "FIFO queue names must end in '.fifo'" ) ;
541
+ throw new ValidationError ( "FIFO queue names must end in '.fifo'" , this ) ;
541
542
}
542
543
if ( ! fifoQueue && queueName . endsWith ( '.fifo' ) ) {
543
- throw new Error ( "Non-FIFO queue name may not end in '.fifo'" ) ;
544
+ throw new ValidationError ( "Non-FIFO queue name may not end in '.fifo'" , this ) ;
544
545
}
545
546
}
546
547
547
548
if ( props . contentBasedDeduplication && ! fifoQueue ) {
548
- throw new Error ( 'Content-based deduplication can only be defined for FIFO queues' ) ;
549
+ throw new ValidationError ( 'Content-based deduplication can only be defined for FIFO queues' , this ) ;
549
550
}
550
551
551
552
if ( props . deduplicationScope && ! fifoQueue ) {
552
- throw new Error ( 'Deduplication scope can only be defined for FIFO queues' ) ;
553
+ throw new ValidationError ( 'Deduplication scope can only be defined for FIFO queues' , this ) ;
553
554
}
554
555
555
556
if ( props . fifoThroughputLimit && ! fifoQueue ) {
556
- throw new Error ( 'FIFO throughput limit can only be defined for FIFO queues' ) ;
557
+ throw new ValidationError ( 'FIFO throughput limit can only be defined for FIFO queues' , this ) ;
557
558
}
558
559
559
560
return {
0 commit comments