Closed
Description
- Review the documentation: https://docs.sentry.io/
- Search for existing issues: https://github.com/getsentry/sentry-javascript/issues
- Use the latest release: https://github.com/getsentry/sentry-javascript/releases
-
Provide a link to the affected event from your Sentry account
Package + Version
-
@sentry/browser
-
@sentry/node
-
raven-js
-
raven-node
(raven for node) - other:
@sentry/serverless
Version:
6.2.5
Description
sentry-javascript/packages/serverless/src/awslambda.ts
Lines 180 to 183 in ce40962
By doing | undefined
, the result is not assignable to a handler from @types/aws-lambda
.
i.e:
import * as Sentry from '@sentry/serverless';
import { APIGatewayTokenAuthorizerHandler, PolicyDocument } from 'aws-lambda';
declare global {
namespace NodeJS {
interface ProcessEnv {
BASIC_AUTH_USERNAME: string;
BASIC_AUTH_PASSWORD: string;
}
}
}
const credentials = Buffer.from(
`${process.env.BASIC_AUTH_USERNAME}:${process.env.BASIC_AUTH_PASSWORD}`
).toString('base64');
const AllowPolicyDocument: PolicyDocument = {
Version: '2012-10-17',
Statement: [
{
Effect: 'Allow',
Action: ['execute-api:Invoke'],
Resource: ['arn:aws:execute-api:ap-southeast-2:*']
}
]
};
export const handler: APIGatewayTokenAuthorizerHandler = Sentry.AWSLambda.wrapHandler(
async event => {
if (event.authorizationToken === `Basic ${credentials}`) {
console.log('successfully authenticated');
return Promise.resolve({
principalId: 'user',
policyDocument: AllowPolicyDocument
});
}
console.info(event);
throw new Error('Unauthorized');
}
);
This produces this error:
src/authorizer/index.ts:28:14 - error TS2322: Type 'Handler<APIGatewayTokenAuthorizerEvent, { principalId: string; policyDocument: PolicyDocument; } | undefined>' is not assignable to type 'APIGatewayTokenAuthorizerHandler'.
Type 'void | Promise<{ principalId: string; policyDocument: PolicyDocument; } | undefined>' is not assignable to type 'void | Promise<APIGatewayAuthorizerResult>'.
Type 'Promise<{ principalId: string; policyDocument: PolicyDocument; } | undefined>' is not assignable to type 'void | Promise<APIGatewayAuthorizerResult>'.
Type 'Promise<{ principalId: string; policyDocument: PolicyDocument; } | undefined>' is not assignable to type 'Promise<APIGatewayAuthorizerResult>'.
Type '{ principalId: string; policyDocument: PolicyDocument; } | undefined' is not assignable to type 'APIGatewayAuthorizerResult'.
Type 'undefined' is not assignable to type 'APIGatewayAuthorizerResult'.
28 export const handler: APIGatewayTokenAuthorizerHandler = Sentry.AWSLambda.wrapHandler(