Skip to content

Commit 47811ab

Browse files
committed
feat(globalaccelerator): throw typed errors
1 parent 0f71ee1 commit 47811ab

File tree

7 files changed

+10
-11
lines changed

7 files changed

+10
-11
lines changed

packages/aws-cdk-lib/.eslintrc.js

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ const noThrowDefaultErrorNotYetSupported = [
2020
'aws-ecs-patterns',
2121
'aws-ecs',
2222
'aws-elasticsearch',
23-
'aws-globalaccelerator',
24-
'aws-globalaccelerator-endpoints',
2523
'aws-iam',
2624
'aws-lambda-destinations',
2725
'aws-lambda-event-sources',
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Token } from '../../core';
1+
import { IConstruct } from 'constructs';
2+
import { Token, ValidationError } from '../../core';
23

3-
export function validateWeight(x?: number) {
4+
export function validateWeight(scope: IConstruct, x?: number) {
45
if (x !== undefined && !Token.isUnresolved(x) && (x < 0 || x > 255)) {
5-
throw new Error(`'weight' must be between 0 and 255, got: ${x}`);
6+
throw new ValidationError(`'weight' must be between 0 and 255, got: ${x}`, scope);
67
}
78
}

packages/aws-cdk-lib/aws-globalaccelerator-endpoints/lib/alb.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class ApplicationLoadBalancerEndpoint implements ga.IEndpoint {
3636
public readonly region?: string;
3737

3838
constructor(private readonly loadBalancer: elbv2.IApplicationLoadBalancer, private readonly options: ApplicationLoadBalancerEndpointOptions = {}) {
39-
validateWeight(options.weight);
39+
validateWeight(loadBalancer, options.weight);
4040
this.region = loadBalancer.env.region;
4141
}
4242

packages/aws-cdk-lib/aws-globalaccelerator-endpoints/lib/eip.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class CfnEipEndpoint implements ga.IEndpoint {
2424
public readonly region?: string;
2525

2626
constructor(private readonly eip: ec2.CfnEIP, private readonly options: CfnEipEndpointProps = {}) {
27-
validateWeight(options.weight);
27+
validateWeight(eip, options.weight);
2828

2929
this.region = Stack.of(eip).region;
3030
}

packages/aws-cdk-lib/aws-globalaccelerator-endpoints/lib/instance.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class InstanceEndpoint implements ga.IEndpoint {
3636
public readonly region?: string;
3737

3838
constructor(private readonly instance: ec2.IInstance, private readonly options: InstanceEndpointProps = {}) {
39-
validateWeight(options.weight);
39+
validateWeight(instance, options.weight);
4040

4141
this.region = instance.env.region;
4242
}

packages/aws-cdk-lib/aws-globalaccelerator-endpoints/lib/nlb.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class NetworkLoadBalancerEndpoint implements ga.IEndpoint {
3636
public readonly region?: string;
3737

3838
constructor(private readonly loadBalancer: elbv2.INetworkLoadBalancer, private readonly options: NetworkLoadBalancerEndpointProps = {}) {
39-
validateWeight(options.weight);
39+
validateWeight(loadBalancer, options.weight);
4040
this.region = loadBalancer.env.region;
4141
}
4242

packages/aws-cdk-lib/aws-globalaccelerator/lib/accelerator.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,13 @@ export class Accelerator extends cdk.Resource implements IAccelerator {
225225

226226
private validateAcceleratorName(name?: string) {
227227
if (!cdk.Token.isUnresolved(name) && name !== undefined && (name.length < 1 || name.length > 64)) {
228-
throw new Error(`Invalid acceleratorName value ${name}, must have length between 1 and 64, got: ${name.length}`);
228+
throw new cdk.ValidationError(`Invalid acceleratorName value ${name}, must have length between 1 and 64, got: ${name.length}`, this);
229229
}
230230
}
231231

232232
private validateIpAddresses(ipAddresses?: string[]) {
233233
if (ipAddresses !== undefined && (ipAddresses.length < 1 || ipAddresses.length > 2)) {
234-
throw new Error(`Invalid ipAddresses value [${ipAddresses}], you can specify one or two addresses, got: ${ipAddresses.length}`);
234+
throw new cdk.ValidationError(`Invalid ipAddresses value [${ipAddresses}], you can specify one or two addresses, got: ${ipAddresses.length}`, this);
235235
}
236236
}
237237
}

0 commit comments

Comments
 (0)