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".

已提問 6 個月前檢視次數 365 次
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."

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南