How to validate the request body and throw custom validation response in API Gateway

0

I am using serverless framework to provision the API gateway. I've defined the request body schema but whenever I send wrong request body it throwing me error of Invalid request body. Is it possible to customize the body of this error message. For an example if email is a required field and when we send request without email in the request body I need to customize the response as "Email is missing".

1 Answer
0

Hi,

You can customize the message by creating your own request validator and define the error message that it returns.

See https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-method-request-validation.html for all details on how to implement this.

Best,

Didier

profile pictureAWS
EXPERT
answered 6 months ago
  • I have checked this docs, but couldn't find it how to customize the response. In the doc also they mentioned that, "When the validation fails, API Gateway immediately fails the request, returns a 400 error response to the caller, and publishes the validation results in CloudWatch Logs."

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions