@@ -8,7 +8,7 @@ import { IUserPool } from '../../aws-cognito';
8
8
import { ManagedPolicy , Role , IRole , ServicePrincipal } from '../../aws-iam' ;
9
9
import { IFunction } from '../../aws-lambda' ;
10
10
import { ILogGroup , LogGroup , LogRetention , RetentionDays } from '../../aws-logs' ;
11
- import { CfnResource , Duration , Expiration , FeatureFlags , IResolvable , Lazy , Stack , Token } from '../../core' ;
11
+ import { CfnResource , Duration , Expiration , FeatureFlags , IResolvable , Lazy , Stack , Token , ValidationError } from '../../core' ;
12
12
import * as cxapi from '../../cx-api' ;
13
13
14
14
/**
@@ -578,7 +578,7 @@ export class GraphqlApi extends GraphqlApiBase {
578
578
if ( this . definition . schema ) {
579
579
return this . definition . schema ;
580
580
}
581
- throw new Error ( 'Schema does not exist for AppSync merged APIs.' ) ;
581
+ throw new ValidationError ( 'Schema does not exist for AppSync merged APIs.' , this ) ;
582
582
}
583
583
584
584
/**
@@ -619,19 +619,19 @@ export class GraphqlApi extends GraphqlApiBase {
619
619
this . validateAuthorizationProps ( modes ) ;
620
620
621
621
if ( ! props . schema && ! props . definition ) {
622
- throw new Error ( 'You must specify a GraphQL schema or source APIs in property definition.' ) ;
622
+ throw new ValidationError ( 'You must specify a GraphQL schema or source APIs in property definition.' , this ) ;
623
623
}
624
624
if ( ( props . schema !== undefined ) === ( props . definition !== undefined ) ) {
625
- throw new Error ( 'You cannot specify both properties schema and definition.' ) ;
625
+ throw new ValidationError ( 'You cannot specify both properties schema and definition.' , this ) ;
626
626
}
627
627
if ( props . queryDepthLimit !== undefined && ( props . queryDepthLimit < 0 || props . queryDepthLimit > 75 ) ) {
628
- throw new Error ( 'You must specify a query depth limit between 0 and 75.' ) ;
628
+ throw new ValidationError ( 'You must specify a query depth limit between 0 and 75.' , this ) ;
629
629
}
630
630
if ( props . resolverCountLimit !== undefined && ( props . resolverCountLimit < 0 || props . resolverCountLimit > 10000 ) ) {
631
- throw new Error ( 'You must specify a resolver count limit between 0 and 10000.' ) ;
631
+ throw new ValidationError ( 'You must specify a resolver count limit between 0 and 10000.' , this ) ;
632
632
}
633
633
if ( ! Token . isUnresolved ( props . ownerContact ) && props . ownerContact !== undefined && ( props . ownerContact . length > 256 ) ) {
634
- throw new Error ( 'You must specify `ownerContact` as a string of 256 characters or less.' ) ;
634
+ throw new ValidationError ( 'You must specify `ownerContact` as a string of 256 characters or less.' , this ) ;
635
635
}
636
636
637
637
this . definition = props . schema ? Definition . fromSchema ( props . schema ) : props . definition ! ;
@@ -786,24 +786,24 @@ export class GraphqlApi extends GraphqlApiBase {
786
786
787
787
private validateAuthorizationProps ( modes : AuthorizationMode [ ] ) {
788
788
if ( modes . filter ( ( mode ) => mode . authorizationType === AuthorizationType . LAMBDA ) . length > 1 ) {
789
- throw new Error ( 'You can only have a single AWS Lambda function configured to authorize your API.' ) ;
789
+ throw new ValidationError ( 'You can only have a single AWS Lambda function configured to authorize your API.' , this ) ;
790
790
}
791
791
modes . map ( ( mode ) => {
792
792
if ( mode . authorizationType === AuthorizationType . OIDC && ! mode . openIdConnectConfig ) {
793
- throw new Error ( 'Missing OIDC Configuration' ) ;
793
+ throw new ValidationError ( 'Missing OIDC Configuration' , this ) ;
794
794
}
795
795
if ( mode . authorizationType === AuthorizationType . USER_POOL && ! mode . userPoolConfig ) {
796
- throw new Error ( 'Missing User Pool Configuration' ) ;
796
+ throw new ValidationError ( 'Missing User Pool Configuration' , this ) ;
797
797
}
798
798
if ( mode . authorizationType === AuthorizationType . LAMBDA && ! mode . lambdaAuthorizerConfig ) {
799
- throw new Error ( 'Missing Lambda Configuration' ) ;
799
+ throw new ValidationError ( 'Missing Lambda Configuration' , this ) ;
800
800
}
801
801
} ) ;
802
802
if ( modes . filter ( ( mode ) => mode . authorizationType === AuthorizationType . API_KEY ) . length > 1 ) {
803
- throw new Error ( 'You can\'t duplicate API_KEY configuration. See https://docs.aws.amazon.com/appsync/latest/devguide/security.html' ) ;
803
+ throw new ValidationError ( 'You can\'t duplicate API_KEY configuration. See https://docs.aws.amazon.com/appsync/latest/devguide/security.html' , this ) ;
804
804
}
805
805
if ( modes . filter ( ( mode ) => mode . authorizationType === AuthorizationType . IAM ) . length > 1 ) {
806
- throw new Error ( 'You can\'t duplicate IAM configuration. See https://docs.aws.amazon.com/appsync/latest/devguide/security.html' ) ;
806
+ throw new ValidationError ( 'You can\'t duplicate IAM configuration. See https://docs.aws.amazon.com/appsync/latest/devguide/security.html' , this ) ;
807
807
}
808
808
}
809
809
@@ -824,16 +824,16 @@ export class GraphqlApi extends GraphqlApiBase {
824
824
*/
825
825
public addEnvironmentVariable ( key : string , value : string ) {
826
826
if ( this . definition . sourceApiOptions ) {
827
- throw new Error ( 'Environment variables are not supported for merged APIs' ) ;
827
+ throw new ValidationError ( 'Environment variables are not supported for merged APIs' , this ) ;
828
828
}
829
829
if ( ! Token . isUnresolved ( key ) && ! / ^ [ A - Z a - z ] + \w * $ / . test ( key ) ) {
830
- throw new Error ( `Key '${ key } ' must begin with a letter and can only contain letters, numbers, and underscores` ) ;
830
+ throw new ValidationError ( `Key '${ key } ' must begin with a letter and can only contain letters, numbers, and underscores` , this ) ;
831
831
}
832
832
if ( ! Token . isUnresolved ( key ) && ( key . length < 2 || key . length > 64 ) ) {
833
- throw new Error ( `Key '${ key } ' must be between 2 and 64 characters long, got ${ key . length } ` ) ;
833
+ throw new ValidationError ( `Key '${ key } ' must be between 2 and 64 characters long, got ${ key . length } ` , this ) ;
834
834
}
835
835
if ( ! Token . isUnresolved ( value ) && value . length > 512 ) {
836
- throw new Error ( `Value for '${ key } ' is too long. Values can be up to 512 characters long, got ${ value . length } ` ) ;
836
+ throw new ValidationError ( `Value for '${ key } ' is too long. Values can be up to 512 characters long, got ${ value . length } ` , this ) ;
837
837
}
838
838
839
839
this . environmentVariables [ key ] = value ;
@@ -926,7 +926,7 @@ export class GraphqlApi extends GraphqlApiBase {
926
926
*/
927
927
public get appSyncDomainName ( ) : string {
928
928
if ( ! this . domainNameResource ) {
929
- throw new Error ( 'Cannot retrieve the appSyncDomainName without a domainName configuration' ) ;
929
+ throw new ValidationError ( 'Cannot retrieve the appSyncDomainName without a domainName configuration' , this ) ;
930
930
}
931
931
return this . domainNameResource . attrAppSyncDomainName ;
932
932
}
0 commit comments