@@ -14,14 +14,8 @@ const sqsRecordHandler = (record: SQSRecord): string => {
14
14
return body ;
15
15
} ;
16
16
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 ) ) ;
25
19
26
20
const kinesisRecordHandler = ( record : KinesisStreamRecord ) : string => {
27
21
const body = record . kinesis . data ;
@@ -34,14 +28,7 @@ const kinesisRecordHandler = (record: KinesisStreamRecord): string => {
34
28
35
29
const asyncKinesisRecordHandler = async (
36
30
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 ) ) ;
45
32
46
33
const dynamodbRecordHandler = ( record : DynamoDBRecord ) : object => {
47
34
const body = record . dynamodb ?. NewImage ?. Message || { S : 'fail' } ;
@@ -55,12 +42,7 @@ const dynamodbRecordHandler = (record: DynamoDBRecord): object => {
55
42
const asyncDynamodbRecordHandler = async (
56
43
record : DynamoDBRecord
57
44
) : 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 ) ) ;
64
46
} ;
65
47
66
48
const handlerWithContext = ( record : SQSRecord , context : Context ) : string => {
@@ -79,15 +61,7 @@ const asyncHandlerWithContext = async (
79
61
record : SQSRecord ,
80
62
context : Context
81
63
) : 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 ) ) ;
91
65
} ;
92
66
93
67
export {
0 commit comments