-
Notifications
You must be signed in to change notification settings - Fork 88
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(v2): Validation failures return 400s #1489
feat(v2): Validation failures return 400s #1489
Conversation
…d returned as a 400 error
powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/ValidationE2ET.java
Outdated
Show resolved
Hide resolved
powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/ValidationE2ET.java
Outdated
Show resolved
Hide resolved
...on/src/main/java/software/amazon/lambda/powertools/validation/internal/ValidationAspect.java
Outdated
Show resolved
Hide resolved
...on/src/main/java/software/amazon/lambda/powertools/validation/internal/ValidationAspect.java
Outdated
Show resolved
Hide resolved
...are/amazon/lambda/powertools/validation/internal/HandledResponseEventsArgumentsProvider.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above comments.
Additional point that we completely forgot: it would be great to make the my idea:
@scottgerring what do you think? |
This is a great idea - I think PT should aspire to "magically do what you'd expect" when you combine modules. We'd need to pay special attention to the coupling between the modules - explicitly maven coupling between batch<->validation is IMHO a non-starter. Perhaps we could pull validation exceptions into their own package, or something 🤷 - i've not thought about this in depth, but I think how this coupling would work will be decisive here. @jeromevdl pragmatically we could also treat this integration in a subsequent PR. WDYT? |
I agree we could do that in another PR: #1496 Regarding the coupling, there should not be any dependency between the 2 modules. And I think there won't be any.
Finger in the nose ?! |
…ation exception
...dlers/validation-alb-event/src/main/java/software/amazon/lambda/powertools/e2e/Function.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last couple of things + rebase v2 and we should be good
...dlers/validation-alb-event/src/main/java/software/amazon/lambda/powertools/e2e/Function.java
Outdated
Show resolved
Hide resolved
…d returned as a 400 error
…ation exception
80ceb05
to
a414353
Compare
@jeromevdl let's merge this when the build succeeds |
@skal111 it looks like you are using Java11+ collection helpers - if you can port that back so the java 8 build succeeds we can merge this! |
APIGatewayV2HTTPEvent event = new APIGatewayV2HTTPEvent(); | ||
event.setBody("{" + | ||
" \"id\": 1," + | ||
" \"name\": \"Lampshade\"" + | ||
"}"); | ||
event.setHeaders(Map.of("header1", "value1")); | ||
|
||
APIGatewayV2HTTPResponse response = handler.handleRequest(event, context); | ||
assertThat(response.getBody()).isNotBlank(); | ||
assertThat(response.getStatusCode()).isEqualTo(400); | ||
assertThat(response.getHeaders()).isEmpty(); | ||
assertThat(response.getMultiValueHeaders()).isEmpty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
APIGatewayV2HTTPEvent event = new APIGatewayV2HTTPEvent(); | |
event.setBody("{" + | |
" \"id\": 1," + | |
" \"name\": \"Lampshade\"" + | |
"}"); | |
event.setHeaders(Map.of("header1", "value1")); | |
APIGatewayV2HTTPResponse response = handler.handleRequest(event, context); | |
assertThat(response.getBody()).isNotBlank(); | |
assertThat(response.getStatusCode()).isEqualTo(400); | |
assertThat(response.getHeaders()).isEmpty(); | |
assertThat(response.getMultiValueHeaders()).isEmpty(); | |
APIGatewayV2HTTPEvent event = new APIGatewayV2HTTPEvent(); | |
event.setBody("{" + | |
" \"id\": 1," + | |
" \"name\": \"Lampshade\"" + | |
"}"); | |
event.setHeaders(Map.of("header1", "value1")); | |
APIGatewayV2HTTPResponse response = handler.handleRequest(event, context); | |
assertThat(response.getBody()).isNotBlank(); | |
assertThat(response.getStatusCode()).isEqualTo(400); | |
assertThat(response.getHeaders()).isEmpty(); | |
assertThat(response.getMultiValueHeaders()).isEmpty(); |
...rc/test/java/software/amazon/lambda/powertools/validation/internal/ValidationAspectTest.java
Outdated
Show resolved
Hide resolved
...rc/test/java/software/amazon/lambda/powertools/validation/internal/ValidationAspectTest.java
Outdated
Show resolved
Hide resolved
...rc/test/java/software/amazon/lambda/powertools/validation/internal/ValidationAspectTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you @skal111
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
I've tested the e2e locally, it's ok! |
api gateway events validation will be catched and returned as a 400 error
#1298
Description of changes:
ValidationException for events of type APIGateway are catched and transformed into a valid response (status 400).
Checklist
Breaking change checklist
RFC issue #:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.