File tree 2 files changed +24
-0
lines changed
2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,14 @@ module.exports.serverless = appFn => {
57
57
// Convert the payload to an Object if API Gateway stringifies it
58
58
event . body = ( typeof event . body === 'string' ) ? JSON . parse ( event . body ) : event . body
59
59
60
+ // Bail for null body
61
+ if ( ! event . body ) {
62
+ return context . done ( null , {
63
+ statusCode : 400 ,
64
+ body : 'Event body is null.'
65
+ } )
66
+ }
67
+
60
68
// Do the thing
61
69
console . log ( `Received event ${ e } ${ event . body . action ? ( '.' + event . body . action ) : '' } ` )
62
70
if ( event ) {
Original file line number Diff line number Diff line change @@ -34,4 +34,20 @@ describe('serverless-lambda', () => {
34
34
expect ( context . done ) . toHaveBeenCalled ( )
35
35
expect ( spy ) . toHaveBeenCalled ( )
36
36
} )
37
+
38
+ it ( 'responds with a 400 error when body is null' , async ( ) => {
39
+ const event = {
40
+ body : null ,
41
+ headers : {
42
+ 'X-Github-Event' : 'issues' ,
43
+ 'x-github-delivery' : 123
44
+ }
45
+ }
46
+
47
+ await handler ( event , context )
48
+ expect ( context . done ) . toHaveBeenCalledWith ( null , expect . objectContaining ( {
49
+ statusCode : 400
50
+ } ) )
51
+ expect ( spy ) . not . toHaveBeenCalled ( )
52
+ } )
37
53
} )
You can’t perform that action at this time.
0 commit comments