title: Lambda custom authorize, how to return custom message?
body: <p>i'm using serverless-framework, node.js and typescript for my service. I have a custom authorizer where I fetch from external service some data and depending on the response from that service I want to return such an error code in my lambda.</p>
  <p>The problem is that each time the response from the authorizer is (no matter how I return the error and what error and what status code it passes):</p>
  <pre><code>{
    &quot;statusCode&quot;: 403,
    &quot;error&quot;: &quot;Forbidden&quot;,
    &quot;message&quot;: &quot;No principalId set on the Response&quot;
  }
  </code></pre>
  <p>Is this the specifics of the custom authorizer and nothing else can be returned or is it possible to modify the response somehow?</p>
  <p>serverless.yml</p>
  <pre><code>...
  functions:
    users:
        handler: lambdas/users/handler.main
        events:
          - http:
              path: /users
              method: GET
              private: true
              authorizer:
                name: customAuthorizer
                resultTtlInSeconds: 0
    customAuthorizer:
        handler: lambdas/custom-authorizer/handler.handler
        environment:
          APP_NAME: ${env:APP_NAME} 
     ...
  </code></pre>
  <p>and this is a simply code from my handler</p>
  <p>handler.ts</p>
  <pre><code>export async function handler(event: APIGatewayTokenAuthorizerEvent, context: Context): Promise&lt;any&gt; {
    context.callbackWaitsForEmptyEventLoop = false;
    try {
      if (!event.authorizationToken) {
        throw new HttpError(&quot;Unauthorized&quot;, 401);
      }
  
      const hasAccess = await fetchingPolicyFromExternalService(event.authorizationToken);
      if (!hasAccess) {
        throw new HttpError(&quot;Forbidden&quot;, 403);
      }
  
      const policyDocument = generatePolicy(event, &quot;Allow&quot;); //generate policy for Allow user to invoke api
  
      return policyDocument;
    } catch (error) {
      if (error instanceof HttpError) {
        return {
          statusCode: error.status,
          body: error.message,
        };
      }
      return {
        statusCode: 500,
        body: &quot;UnknownError&quot;,
      };
    }
  }
  </code></pre>