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 réponse
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
répondu il y a 6 mois
  • 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."

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions