Repository: serverless/serverless (JavaScript) — Bug Fix

Issue:
When http indenting in yml isn't correct error message doesn't mention function name that has the issue
# This is a Bug Report

## Description

When a function is improperly indented like so (note path & method are not properly indented under http):

```
  pingfunction:
    handler: handler.ping
    events:
      - http:
      path: api/ping
      method: get
```

For bug reports:
The actual error message is `Cannot read property 'path' of null` and doesn't mention the function name with the problem.

* What did you expect should have happened?
Expected the function name to be in the error message to make it easier to find the source of this generic error.

* What was the config you used?
release

* What stacktrace or error message from your provider did you see?
none

## Additional Data

* ***Serverless Framework Version you're using***:
1.15.3

* ***Operating System***:
macOS

* ***Stack Trace***:
none

* ***Provider Error messages***:



Discussion:

Resolving patch:
diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js
index 97f99637f2c..fa7f7924366 100644
--- a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js
+++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js
@@ -150,7 +150,7 @@ module.exports = {
   },
 
   getHttpPath(http, functionName) {
-    if (typeof http.path === 'string') {
+    if (http && typeof http.path === 'string') {
       return http.path.replace(/^\//, '').replace(/\/$/, '');
     }
     const errorMessage = [
@@ -158,6 +158,7 @@ module.exports = {
       ' for http event in serverless.yml.',
       ' If you define an http event, make sure you pass a valid value for it,',
       ' either as string syntax, or object syntax.',
+      ' Please check the indentation of your config values if you use the object syntax.',
       ' Please check the docs for more options.',
     ].join('');
     throw new this.serverless.classes.Error(errorMessage);


Test patch:
diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.test.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.test.js
index 7ead5365f74..6206c757b5a 100644
--- a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.test.js
+++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.test.js
@@ -61,6 +61,25 @@ describe('#validate()', () => {
     expect(() => awsCompileApigEvents.validate()).to.throw(Error);
   });
 
+  it('should throw a helpful error if http event type object doesn\'t have a path property', () => {
+    /**
+     * This can happen with surprising subtle syntax error such as when path is not
+     * indented under http in yml.
+     */
+    awsCompileApigEvents.serverless.service.functions = {
+      first: {
+        events: [
+          {
+            http: null,
+          },
+        ],
+      },
+    };
+
+    expect(() => awsCompileApigEvents.validate()).to
+      .throw(/invalid "path" property in function "first"/);
+  });
+
   it('should validate the http events "path" property', () => {
     awsCompileApigEvents.serverless.service.functions = {
       first: {