You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an api gateway resolver with numerous routes and validation enabled. For route "/a" the default if the response cannot be validated against the route's function's annotation would be a 422 response. I want route "/b" however, to return a 500 if its response could not be validated and route "/c" to return a 403.
Hey @amin-farjadi! Thanks a lot for opening this issue and sorry for late reply! Since now we have the global response validation http code, we can move on per route implementation. I have some considerations:
1/ What about response_validation_error_http_code instead of custom_response_validation_http_code?
2/ In my opinion if a customer set response validation code per route, it should take precedence on the global one, what do you think? for example:
fromaws_lambda_powertools.event_handlerimportAPIGatewayRestResolverapp=APIGatewayRestResolver(
enable_validation=True,
response_validation_error_http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
)
@app.get("/c",response_validation_error_http_code=403, # will overwrite the global, returning 403)defhandler_route_c() ->Model:
return {"age": 18} # type: ignore@app.get("/d"# will return the global one, which is 500)defhandler_route_d() ->Model:
return {"age": 18} # type: ignore
Use case
I have an api gateway resolver with numerous routes and validation enabled. For route "/a" the default if the response cannot be validated against the route's function's annotation would be a
422
response. I want route "/b" however, to return a500
if its response could not be validated and route "/c" to return a403
.Solution/User Experience
Alternative solutions
Acknowledgment
The text was updated successfully, but these errors were encountered: