feat(v2): Validation failures return 400s #1489
feat(v2): Validation failures return 400s #1489jeromevdl merged 21 commits intoaws-powertools:v2from skal111:feat/1298-validation-400
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
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
|
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
jeromevdl
left a comment
There was a problem hiding this comment.
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
|
@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.
| 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
|
Kudos, SonarCloud Quality Gate passed!
|
|
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.