@@ -5,6 +5,7 @@ import { HttpRouteIntegration } from './integration';
5
5
import { CfnRoute , CfnRouteProps } from '.././index' ;
6
6
import * as iam from '../../../aws-iam' ;
7
7
import { Aws , Resource } from '../../../core' ;
8
+ import { UnscopedValidationError , ValidationError } from '../../../core/lib/errors' ;
8
9
import { IRoute } from '../common' ;
9
10
10
11
/**
@@ -84,7 +85,7 @@ export class HttpRouteKey {
84
85
*/
85
86
public static with ( path : string , method ?: HttpMethod ) {
86
87
if ( path !== '/' && ( ! path . startsWith ( '/' ) || path . endsWith ( '/' ) ) ) {
87
- throw new Error ( 'A route path must always start with a "/" and not end with a "/"' ) ;
88
+ throw new UnscopedValidationError ( 'A route path must always start with a "/" and not end with a "/"' ) ;
88
89
}
89
90
return new HttpRouteKey ( method , path ) ;
90
91
}
@@ -200,7 +201,7 @@ export class HttpRoute extends Resource implements IHttpRoute {
200
201
} ) ;
201
202
202
203
if ( this . authBindResult && ! ( this . authBindResult . authorizationType in HttpRouteAuthorizationType ) ) {
203
- throw new Error ( `authorizationType should either be AWS_IAM, JWT, CUSTOM, or NONE but was '${ this . authBindResult . authorizationType } '` ) ;
204
+ throw new ValidationError ( `authorizationType should either be AWS_IAM, JWT, CUSTOM, or NONE but was '${ this . authBindResult . authorizationType } '` , scope ) ;
204
205
}
205
206
206
207
let authorizationScopes = this . authBindResult ?. authorizationScopes ;
@@ -236,7 +237,7 @@ export class HttpRoute extends Resource implements IHttpRoute {
236
237
// When the user has provided a path with path variables, we replace the
237
238
// path variable and all that follows with a wildcard.
238
239
if ( path . length > 1000 ) {
239
- throw new Error ( `Path is too long: ${ path } ` ) ;
240
+ throw new ValidationError ( `Path is too long: ${ path } ` , this ) ;
240
241
} ;
241
242
const iamPath = path . replace ( / \{ .* ?\} .* / , '*' ) ;
242
243
@@ -245,12 +246,12 @@ export class HttpRoute extends Resource implements IHttpRoute {
245
246
246
247
public grantInvoke ( grantee : iam . IGrantable , options : GrantInvokeOptions = { } ) : iam . Grant {
247
248
if ( ! this . authBindResult || this . authBindResult . authorizationType !== HttpRouteAuthorizationType . AWS_IAM ) {
248
- throw new Error ( 'To use grantInvoke, you must use IAM authorization' ) ;
249
+ throw new ValidationError ( 'To use grantInvoke, you must use IAM authorization' , this ) ;
249
250
}
250
251
251
252
const httpMethods = Array . from ( new Set ( options . httpMethods ?? [ this . method ] ) ) ;
252
253
if ( this . method !== HttpMethod . ANY && httpMethods . some ( method => method !== this . method ) ) {
253
- throw new Error ( 'This route does not support granting invoke for all requested http methods' ) ;
254
+ throw new ValidationError ( 'This route does not support granting invoke for all requested http methods' , this ) ;
254
255
}
255
256
256
257
const resourceArns = httpMethods . map ( httpMethod => {
0 commit comments