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 Resposta
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
ESPECIALISTA
respondido há 6 meses
  • 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."

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas