22
33const _ = require ( 'lodash' ) ;
44
5- const DEFAULT_STATUS_CODES = {
6- 200 : {
7- pattern : '' ,
8- } ,
9- 400 : {
10- pattern : '.*\\[400\\].*' ,
11- } ,
12- 401 : {
13- pattern : '.*\\[401\\].*' ,
14- } ,
15- 403 : {
16- pattern : '.*\\[403\\].*' ,
17- } ,
18- 404 : {
19- pattern : '.*\\[404\\].*' ,
20- } ,
21- 422 : {
22- pattern : '.*\\[422\\].*' ,
23- } ,
24- 500 : {
25- pattern : '.*(Process\\s?exited\\s?before\\s?completing\\s?request|\\[500\\]).*' ,
26- } ,
27- 502 : {
28- pattern : '.*\\[502\\].*' ,
29- } ,
30- 504 : {
31- pattern : '.*\\[504\\].*' ,
32- } ,
33- } ;
34-
355module . exports = {
366 httpValidate ( ) {
377 const events = [ ] ;
@@ -42,23 +12,8 @@ module.exports = {
4212 _ . forEach ( stateMachineObj . events , ( event ) => {
4313 if ( _ . has ( event , 'http' ) ) {
4414 const http = this . getHttp ( event , stateMachineName ) ;
45-
4615 http . path = this . getHttpPath ( http , stateMachineName ) ;
4716 http . method = this . getHttpMethod ( http , stateMachineName ) ;
48- http . request = { } ;
49-
50- http . request . passThrough = 'NEVER' ;
51- http . response = { } ;
52-
53- if ( http . response . statusCodes ) {
54- http . response . statusCodes = _ . assign ( { } , http . response . statusCodes ) ;
55-
56- if ( ! _ . some ( http . response . statusCodes , code => code . pattern === '' ) ) {
57- http . response . statusCodes [ '200' ] = DEFAULT_STATUS_CODES [ '200' ] ;
58- }
59- } else {
60- http . response . statusCodes = DEFAULT_STATUS_CODES ;
61- }
6217
6318 events . push ( {
6419 stateMachineName,
@@ -85,7 +40,7 @@ module.exports = {
8540 } ) ;
8641 } ,
8742
88- getHttp ( event , functionName ) {
43+ getHttp ( event , stateMachineName ) {
8944 if ( typeof event . http === 'object' ) {
9045 return event . http ;
9146 } else if ( typeof event . http === 'string' ) {
@@ -95,7 +50,7 @@ module.exports = {
9550 } ;
9651 }
9752 const errorMessage = [
98- `Invalid http event in function "${ functionName } "` ,
53+ `Invalid http event in stateMachine "${ stateMachineName } "` ,
9954 ' in serverless.yml.' ,
10055 ' If you define an http event, make sure you pass a valid value for it,' ,
10156 ' either as string syntax, or object syntax.' ,
@@ -104,12 +59,12 @@ module.exports = {
10459 throw new this . serverless . classes . Error ( errorMessage ) ;
10560 } ,
10661
107- getHttpPath ( http , functionName ) {
62+ getHttpPath ( http , stateMachineName ) {
10863 if ( typeof http . path === 'string' ) {
10964 return http . path . replace ( / ^ \/ / , '' ) . replace ( / \/ $ / , '' ) ;
11065 }
11166 const errorMessage = [
112- `Missing or invalid "path" property in function "${ functionName } "` ,
67+ `Missing or invalid "path" property in stateMachine "${ stateMachineName } "` ,
11368 ' for http event in serverless.yml.' ,
11469 ' If you define an http event, make sure you pass a valid value for it,' ,
11570 ' either as string syntax, or object syntax.' ,
@@ -118,7 +73,7 @@ module.exports = {
11873 throw new this . serverless . classes . Error ( errorMessage ) ;
11974 } ,
12075
121- getHttpMethod ( http , functionName ) {
76+ getHttpMethod ( http , stateMachineName ) {
12277 if ( typeof http . method === 'string' ) {
12378 const method = http . method . toLowerCase ( ) ;
12479
@@ -127,15 +82,15 @@ module.exports = {
12782 ] ;
12883 if ( allowedMethods . indexOf ( method ) === - 1 ) {
12984 const errorMessage = [
130- `Invalid APIG method "${ http . method } " in function "${ functionName } ".` ,
85+ `Invalid APIG method "${ http . method } " in stateMachine "${ stateMachineName } ".` ,
13186 ` AWS supported methods are: ${ allowedMethods . join ( ', ' ) } .` ,
13287 ] . join ( '' ) ;
13388 throw new this . serverless . classes . Error ( errorMessage ) ;
13489 }
13590 return method ;
13691 }
13792 const errorMessage = [
138- `Missing or invalid "method" property in function "${ functionName } "` ,
93+ `Missing or invalid "method" property in stateMachine "${ stateMachineName } "` ,
13994 ' for http event in serverless.yml.' ,
14095 ' If you define an http event, make sure you pass a valid value for it,' ,
14196 ' either as string syntax, or object syntax.' ,
0 commit comments