# {"message": "Internal server error"} \<- I've read the docs, the forums...?

**URL:** <https://forum.serverless.com/t/message-internal-server-error-ive-read-the-docs-the-forums/4275>\
**Category:** Serverless Framework\
**Created:** [April 17, 2018, 3:06am UTC](https://forum.serverless.com/t/message-internal-server-error-ive-read-the-docs-the-forums/4275 "2018-04-17T03:06:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![3boysdad](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/3boysdad/32/2071_2.png) [@3boysdad](https://forum.serverless.com/u/3boysdad)\
**Post date:** [April 17, 2018, 3:06am UTC](https://forum.serverless.com/t/message-internal-server-error-ive-read-the-docs-the-forums/4275/1 "2018-04-17T03:06:15Z")

</div>

Here’s my yml file -\>

service: presto-contact-service

plugins:

- serverless-plugin-include-dependencies

provider:  
name: aws  
runtime: nodejs6.10  
stage: dev  
region: us-west-2

iamRoleStatements:  
- Effect: “Allow”  
Action:  
- “ses:SendEmail”  
Resource: “\*”

functions:  
newcontact:  
handler: handler.newcontact  
events:  
- http:  
path: /  
method: get  
cors: true

and my simple function.

‘use strict’;

const querystring = require(‘querystring’);  
const AWS = require(‘aws-sdk’);  
const emailer = require(‘ses-email-sender’);

module.exports.newcontact = (event, context, callback) =\> {

// get the data on the form in an array.  
var formAttributes = querystring.parse(event.body);

console.log(formAttributes);

const response = {  
statusCode: 200,  
headers: {  
“Access-Control-Allow-Origin” : “\*”,  
“Access-Control-Allow-Credentials” : true, // probably 100% unnecessary…  
“Content-Type” : “application/json” // doesn’t matter if this is here or not on the response.  
},  
body: JSON.stringify({ message: ‘great!’, input: event }),  
};

callback(null, response);  
};

In looking at the log files generated by the lambda function, the function is working great. however, the gateway api is still barfing and spitting back a 502 error. honestly…i’ve seen a bit of comments around this and they generally fall into the category of “you aren’t using the right response object in the callback…”. but i am pretty sure I am here…

---

<div class="post-metadata">

**Author:** ![3boysdad](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/3boysdad/32/2071_2.png) [@3boysdad](https://forum.serverless.com/u/3boysdad)\
**Post date:** [April 17, 2018, 2:45pm UTC](https://forum.serverless.com/t/message-internal-server-error-ive-read-the-docs-the-forums/4275/2 "2018-04-17T14:45:07Z")

</div>

Of course a good night’s sleep solved my problem…my client code was still using GET in the .ajax call… event.body will be empty in that instance…so how about some error handling…for an error on a GET.

module.exports.newcontact = (event, context, callback) =\> {  
console.log(event);  
console.log(‘iam here!’);

if ( event.httpMethod === ‘GET’) {  
const response = {  
statusCode: 404,  
headers: {  
“Access-Control-Allow-Origin” : “\*”,  
“Access-Control-Allow-Credentials” : true,  
“Content-Type” : “application/json”  
},  
body: JSON.stringify({  
message: ‘GET generated an error’,  
input: event,  
}),  
};

```
callback(null, response);

```

} else {  
console.log(‘POST’);  
console.log(event.body);  
var formAttributes = querystring.parse(event.body);

```
console.log(formAttributes['fname']);
console.log(formAttributes['lname']);
console.log(formAttributes['email']);
console.log('iam here - 2!');

sendEmailWithOutAttachment(formAttributes['email'], companyEmail, 'Thank you', 'Thank you for your interest we got your request', function() {
  const response = {
    statusCode: 200,
    headers: {
      "Access-Control-Allow-Origin" : "*",
      "Access-Control-Allow-Credentials" : true,
      "Content-Type" : "application/json"
      },
      body: JSON.stringify({
      message: formAttributes['fname'] + ' Go Serverless v1.0! Your function executed successfully!',
      input: event,
    }),
  };

  callback(null, response);
});

```

};  
};
