@@ -14,14 +14,8 @@ const sqsRecordHandler = (record: SQSRecord): string => {
1414 return body ;
1515} ;
1616
17- const asyncSqsRecordHandler = async ( record : SQSRecord ) : Promise < string > => {
18- const body = record . body ;
19- if ( body . includes ( 'fail' ) ) {
20- throw Error ( 'Failed to process record.' ) ;
21- }
22-
23- return body ;
24- } ;
17+ const asyncSqsRecordHandler = async ( record : SQSRecord ) : Promise < string > =>
18+ Promise . resolve ( sqsRecordHandler ( record ) ) ;
2519
2620const kinesisRecordHandler = ( record : KinesisStreamRecord ) : string => {
2721 const body = record . kinesis . data ;
@@ -34,14 +28,7 @@ const kinesisRecordHandler = (record: KinesisStreamRecord): string => {
3428
3529const asyncKinesisRecordHandler = async (
3630 record : KinesisStreamRecord
37- ) : Promise < string > => {
38- const body = record . kinesis . data ;
39- if ( body . includes ( 'fail' ) ) {
40- throw Error ( 'Failed to process record.' ) ;
41- }
42-
43- return body ;
44- } ;
31+ ) : Promise < string > => Promise . resolve ( kinesisRecordHandler ( record ) ) ;
4532
4633const dynamodbRecordHandler = ( record : DynamoDBRecord ) : object => {
4734 const body = record . dynamodb ?. NewImage ?. Message || { S : 'fail' } ;
@@ -55,12 +42,7 @@ const dynamodbRecordHandler = (record: DynamoDBRecord): object => {
5542const asyncDynamodbRecordHandler = async (
5643 record : DynamoDBRecord
5744) : Promise < object > => {
58- const body = record . dynamodb ?. NewImage ?. Message || { S : 'fail' } ;
59- if ( body . S ?. includes ( 'fail' ) ) {
60- throw Error ( 'Failed to process record.' ) ;
61- }
62-
63- return body ;
45+ return Promise . resolve ( dynamodbRecordHandler ( record ) ) ;
6446} ;
6547
6648const handlerWithContext = ( record : SQSRecord , context : Context ) : string => {
@@ -79,15 +61,7 @@ const asyncHandlerWithContext = async (
7961 record : SQSRecord ,
8062 context : Context
8163) : Promise < string > => {
82- try {
83- if ( context . getRemainingTimeInMillis ( ) === 0 ) {
84- throw Error ( 'No time remaining.' ) ;
85- }
86- } catch {
87- throw Error ( `Context possibly malformed. Displaying context:\n${ context } ` ) ;
88- }
89-
90- return Promise . resolve ( record . body ) ;
64+ return Promise . resolve ( handlerWithContext ( record , context ) ) ;
9165} ;
9266
9367export {
0 commit comments