@@ -8,7 +8,7 @@ import { IUserPool } from '../../aws-cognito';
88import { ManagedPolicy , Role , IRole , ServicePrincipal } from '../../aws-iam' ;
99import { IFunction } from '../../aws-lambda' ;
1010import { 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' ;
1212import * as cxapi from '../../cx-api' ;
1313
1414/**
@@ -578,7 +578,7 @@ export class GraphqlApi extends GraphqlApiBase {
578578 if ( this . definition . schema ) {
579579 return this . definition . schema ;
580580 }
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 ) ;
582582 }
583583
584584 /**
@@ -619,19 +619,19 @@ export class GraphqlApi extends GraphqlApiBase {
619619 this . validateAuthorizationProps ( modes ) ;
620620
621621 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 ) ;
623623 }
624624 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 ) ;
626626 }
627627 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 ) ;
629629 }
630630 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 ) ;
632632 }
633633 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 ) ;
635635 }
636636
637637 this . definition = props . schema ? Definition . fromSchema ( props . schema ) : props . definition ! ;
@@ -786,24 +786,24 @@ export class GraphqlApi extends GraphqlApiBase {
786786
787787 private validateAuthorizationProps ( modes : AuthorizationMode [ ] ) {
788788 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 ) ;
790790 }
791791 modes . map ( ( mode ) => {
792792 if ( mode . authorizationType === AuthorizationType . OIDC && ! mode . openIdConnectConfig ) {
793- throw new Error ( 'Missing OIDC Configuration' ) ;
793+ throw new ValidationError ( 'Missing OIDC Configuration' , this ) ;
794794 }
795795 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 ) ;
797797 }
798798 if ( mode . authorizationType === AuthorizationType . LAMBDA && ! mode . lambdaAuthorizerConfig ) {
799- throw new Error ( 'Missing Lambda Configuration' ) ;
799+ throw new ValidationError ( 'Missing Lambda Configuration' , this ) ;
800800 }
801801 } ) ;
802802 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 ) ;
804804 }
805805 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 ) ;
807807 }
808808 }
809809
@@ -824,16 +824,16 @@ export class GraphqlApi extends GraphqlApiBase {
824824 */
825825 public addEnvironmentVariable ( key : string , value : string ) {
826826 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 ) ;
828828 }
829829 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 ) ;
831831 }
832832 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 ) ;
834834 }
835835 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 ) ;
837837 }
838838
839839 this . environmentVariables [ key ] = value ;
@@ -926,7 +926,7 @@ export class GraphqlApi extends GraphqlApiBase {
926926 */
927927 public get appSyncDomainName ( ) : string {
928928 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 ) ;
930930 }
931931 return this . domainNameResource . attrAppSyncDomainName ;
932932 }
0 commit comments