Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(apigatewayv2): throw ValidationError instead of untyped errors #33082

Merged
merged 5 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/aws-cdk-lib/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ baseConfig.rules['import/no-extraneous-dependencies'] = [

// no-throw-default-error
const enableNoThrowDefaultErrorIn = [
'aws-apigatewayv2-integrations',
'aws-apigatewayv2-authorizers',
'aws-lambda',
'aws-rds',
'aws-s3',
Expand All @@ -25,7 +27,6 @@ const enableNoThrowDefaultErrorIn = [
'aws-ssmcontacts',
'aws-ssmincidents',
'aws-ssmquicksetup',
'aws-apigatewayv2-authorizers',
'aws-synthetics',
'aws-route53',
'aws-route53-patterns',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { HttpPrivateIntegration } from './private/integration';
import { HttpRouteIntegrationBindOptions, HttpRouteIntegrationConfig } from '../../../aws-apigatewayv2';
import * as ec2 from '../../../aws-ec2';
import * as elbv2 from '../../../aws-elasticloadbalancingv2';
import { ValidationError } from '../../../core/lib/errors';

/**
* Properties to initialize `HttpAlbIntegration`.
Expand Down Expand Up @@ -33,7 +34,7 @@ export class HttpAlbIntegration extends HttpPrivateIntegration {
vpc = this.listener.loadBalancer.vpc;
}
if (!vpc) {
throw new Error('The vpcLink property must be specified when using an imported Application Listener.');
throw new ValidationError('The vpcLink property must be specified when using an imported Application Listener.', options.scope);
}

const vpcLink = this._configureVpcLink(options, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { HttpPrivateIntegration } from './private/integration';
import { HttpRouteIntegrationBindOptions, HttpRouteIntegrationConfig } from '../../../aws-apigatewayv2';
import * as ec2 from '../../../aws-ec2';
import * as elbv2 from '../../../aws-elasticloadbalancingv2';
import { ValidationError } from '../../../core/lib/errors';

/**
* Properties to initialize `HttpNlbIntegration`.
Expand Down Expand Up @@ -33,7 +34,7 @@ export class HttpNlbIntegration extends HttpPrivateIntegration {
vpc = this.listener.loadBalancer.vpc;
}
if (!vpc) {
throw new Error('The vpcLink property must be specified when using an imported Network Listener.');
throw new ValidationError('The vpcLink property must be specified when using an imported Network Listener.', options.scope);
}

const vpcLink = this._configureVpcLink(options, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
IVpcLink,
} from '../../../../aws-apigatewayv2';
import * as ec2 from '../../../../aws-ec2';
import { ValidationError } from '../../../../core/lib/errors';

/**
* Options required to use an existing vpcLink or configure a new one
Expand Down Expand Up @@ -51,7 +52,7 @@ export abstract class HttpPrivateIntegration extends HttpRouteIntegration {
let vpcLink = configOptions.vpcLink;
if (!vpcLink) {
if (!configOptions.vpc) {
throw new Error('One of vpcLink or vpc should be provided for private integration');
throw new ValidationError('One of vpcLink or vpc should be provided for private integration', bindOptions.scope);
}

vpcLink = bindOptions.route.httpApi.addVpcLink({ vpc: configOptions.vpc });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { HttpPrivateIntegrationOptions } from './base-types';
import { HttpPrivateIntegration } from './private/integration';
import { HttpRouteIntegrationBindOptions, HttpRouteIntegrationConfig } from '../../../aws-apigatewayv2';
import * as servicediscovery from '../../../aws-servicediscovery';
import { ValidationError } from '../../../core/lib/errors';

/**
* Properties to initialize `HttpServiceDiscoveryIntegration`.
Expand All @@ -26,9 +27,9 @@ export class HttpServiceDiscoveryIntegration extends HttpPrivateIntegration {
super(id);
}

public bind(_options: HttpRouteIntegrationBindOptions): HttpRouteIntegrationConfig {
public bind(options: HttpRouteIntegrationBindOptions): HttpRouteIntegrationConfig {
if (!this.props.vpcLink) {
throw new Error('The vpcLink property is mandatory');
throw new ValidationError('The vpcLink property is mandatory', options.scope);
}

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as apigwv2 from '../../../aws-apigatewayv2';
import * as iam from '../../../aws-iam';
import * as sfn from '../../../aws-stepfunctions';
import { ValidationError } from '../../../core/lib/errors';

/**
* Properties to initialize `HttpStepFunctionsIntegration`.
Expand Down Expand Up @@ -51,13 +52,13 @@ export class HttpStepFunctionsIntegration extends apigwv2.HttpRouteIntegration {

public bind(options: apigwv2.HttpRouteIntegrationBindOptions): apigwv2.HttpRouteIntegrationConfig {
if (this.props.subtype && !this.props.subtype.startsWith('StepFunctions-')) {
throw new Error('Subtype must start with `STEPFUNCTIONS_`');
throw new ValidationError('Subtype must start with `STEPFUNCTIONS_`', options.scope);
}
if (
this.props.subtype === apigwv2.HttpIntegrationSubtype.STEPFUNCTIONS_START_SYNC_EXECUTION
&& this.props.stateMachine.stateMachineType === sfn.StateMachineType.STANDARD
) {
throw new Error('Cannot use subtype `STEPFUNCTIONS_START_SYNC_EXECUTION` with a standard type state machine');
throw new ValidationError('Cannot use subtype `STEPFUNCTIONS_START_SYNC_EXECUTION` with a standard type state machine', options.scope);
}

const invokeRole = new iam.Role(options.scope, 'InvokeRole', {
Expand Down
Loading