custom authorizers in Amazon API Gateway 500 error

前端 未结 1 829
时光取名叫无心
时光取名叫无心 2021-01-12 17:09

I use Serverless-Authentication-boilerplate and want to map custom error response. But it always return 500 error.

authorize.js

// Authorize
function         


        
相关标签:
1条回答
  • 2021-01-12 17:41

    After ask to Amazon Web Services.

    Unfortunately the mapping of the Authorizer is not currently configurable and every returned error from a lambda function will map to a 500 status code in API gateway. Moreover, the mapping is performed on an exact string match of the output, so, in order to return the intended 401 Error to the client, you should execute a call to 'context.fail('Unauthorized');.

    Finally, I change

    callback('401 Unauthenticated');
    

    to

    context.fail('Unauthorized');
    

    and work fine.

    Sharing to whom may encounter this.

    0 讨论(0)
提交回复
热议问题