Skip to content
New issue

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

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

Already on GitHub? # to your account

feat(apigatewayv2-authorizers): throw ValidationError instead of untyped errors #33076

Merged
merged 3 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
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const enableNoThrowDefaultErrorIn = [
'aws-ssmcontacts',
'aws-ssmincidents',
'aws-ssmquicksetup',
'aws-apigatewayv2-authorizers',
'aws-synthetics',
'aws-s3-assets',
'aws-s3-deployment',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
HttpRouteAuthorizerConfig,
IHttpRouteAuthorizer,
} from '../../../aws-apigatewayv2';
import { UnscopedValidationError } from '../../../core/lib/errors';

/**
* Properties to initialize HttpJwtAuthorizer.
Expand Down Expand Up @@ -59,7 +60,7 @@ export class HttpJwtAuthorizer implements IHttpRouteAuthorizer {
*/
public get authorizerId(): string {
if (!this.authorizer) {
throw new Error(
throw new UnscopedValidationError(
'Cannot access authorizerId until authorizer is attached to a HttpRoute',
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { ServicePrincipal } from '../../../aws-iam';
import { IFunction } from '../../../aws-lambda';
import { Stack, Duration, Names } from '../../../core';
import { UnscopedValidationError, ValidationError } from '../../../core/lib/errors';

/**
* Specifies the type responses the lambda returns
Expand Down Expand Up @@ -90,7 +91,7 @@ export class HttpLambdaAuthorizer implements IHttpRouteAuthorizer {
*/
public get authorizerId(): string {
if (!this.authorizer) {
throw new Error(
throw new UnscopedValidationError(
'Cannot access authorizerId until authorizer is attached to a HttpRoute',
);
}
Expand All @@ -99,7 +100,7 @@ export class HttpLambdaAuthorizer implements IHttpRouteAuthorizer {

public bind(options: HttpRouteAuthorizerBindOptions): HttpRouteAuthorizerConfig {
if (this.httpApi && (this.httpApi.apiId !== options.route.httpApi.apiId)) {
throw new Error('Cannot attach the same authorizer to multiple Apis');
throw new ValidationError('Cannot attach the same authorizer to multiple Apis', options.scope);
}

if (!this.authorizer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HttpAuthorizer, HttpAuthorizerType, HttpRouteAuthorizerBindOptions, HttpRouteAuthorizerConfig, IHttpRouteAuthorizer } from '../../../aws-apigatewayv2';
import { IUserPool, IUserPoolClient } from '../../../aws-cognito';
import { Stack } from '../../../core';
import { UnscopedValidationError } from '../../../core/lib/errors';

/**
* Properties to initialize HttpUserPoolAuthorizer.
Expand Down Expand Up @@ -59,7 +60,7 @@ export class HttpUserPoolAuthorizer implements IHttpRouteAuthorizer {
*/
public get authorizerId(): string {
if (!this.authorizer) {
throw new Error(
throw new UnscopedValidationError(
'Cannot access authorizerId until authorizer is attached to a HttpRoute',
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { ServicePrincipal } from '../../../aws-iam';
import { IFunction } from '../../../aws-lambda';
import { Stack, Names } from '../../../core';
import { ValidationError } from '../../../core/lib/errors';

/**
* Properties to initialize WebSocketTokenAuthorizer.
Expand Down Expand Up @@ -49,7 +50,7 @@ export class WebSocketLambdaAuthorizer implements IWebSocketRouteAuthorizer {

public bind(options: WebSocketRouteAuthorizerBindOptions): WebSocketRouteAuthorizerConfig {
if (this.webSocketApi && (this.webSocketApi.apiId !== options.route.webSocketApi.apiId)) {
throw new Error('Cannot attach the same authorizer to multiple Apis');
throw new ValidationError('Cannot attach the same authorizer to multiple Apis', options.scope);
}

if (!this.authorizer) {
Expand Down
Loading