2
votes

I'm trying to understand the authorizers in AWS Api Gateway. As I understand, if exception in the logic takes place in authorizer, then we would definitely get 401 with a message unauthorized. Is it possible to return bad request response, or unprocessable entity response?

I found that authorizers work a bit strange:

1) custom authorizers in Amazon API Gateway 500 error

2) https://forums.aws.amazon.com/message.jspa?messageID=753817

1

1 Answers

0
votes

It is possible. There are multiple solutions.

  1. The lambda function can throw a custom exception and you can perform exception based catch in the API gateway to send 400 status code.

  2. Use the deny response but in the context have the reason for deny. When deny happens, code can check for the reason in context and return appropriate response.

Please refer to below links for exception mapping https://docs.aws.amazon.com/apigateway/latest/developerguide/handle-errors-in-lambda-integration.html#handle-custom-errors-in-lambda-integration

http://awspapers.blogspot.com/2018/08/integrate-api-with-lambda-part-5.html