Repository navigation
Closed
Labels
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
| export function wrapHandler<TEvent, TResult>( | |
| handler: Handler<TEvent, TResult>, | |
| wrapOptions: Partial<WrapperOptions> = {}, | |
| ): Handler<TEvent, TResult | undefined> { |
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(
Reacted by Corey Walker
Activity
xr0master commentedon Dec 25, 2021
Hello, I have the same question. Was there a reason to add the
undefinedto types? Since it does not correspond to the AWS lambda types. Of course, this is easy to fix through casting, but it slightly increases the code and constantly needs to do it for each function.ref(serverless): Remove `rethrowAfterCapture` use in AWS lambda wrapp…