File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 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 => {
5757 // Convert the payload to an Object if API Gateway stringifies it
5858 event . body = ( typeof event . body === 'string' ) ? JSON . parse ( event . body ) : event . body
5959
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+
6068 // Do the thing
6169 console . log ( `Received event ${ e } ${ event . body . action ? ( '.' + event . body . action ) : '' } ` )
6270 if ( event ) {
Original file line number Diff line number Diff line change @@ -34,4 +34,20 @@ describe('serverless-lambda', () => {
3434 expect ( context . done ) . toHaveBeenCalled ( )
3535 expect ( spy ) . toHaveBeenCalled ( )
3636 } )
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+ } )
3753} )
You can’t perform that action at this time.
0 commit comments