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개 답변
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
전문가
답변함 6달 전
  • 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."

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠