# {"message": "Internal server error"} on API Gateway responses with 1.5

**URL:** <https://forum.serverless.com/t/message-internal-server-error-on-api-gateway-responses-with-1-5/1117>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [January 14, 2017, 6:20am UTC](https://forum.serverless.com/t/message-internal-server-error-on-api-gateway-responses-with-1-5/1117 "2017-01-14T06:20:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hendry](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/hendry/32/343_2.png) [@hendry](https://forum.serverless.com/u/hendry)\
**Post date:** [January 14, 2017, 6:20am UTC](https://forum.serverless.com/t/message-internal-server-error-on-api-gateway-responses-with-1-5/1117/1 "2017-01-14T06:20:48Z")

</div>

I just want to return the error object. I was hoping `callback(error)` would work but it doesn’t. All I get is {“message”: “Internal server error”} via the API gateway. My error object looks good to go:

```
{ [MessageRejected: Email address is not verified. The following identities failed the check in region US-WEST-2: john@example.com]
  message: 'Email address is not verified. The following identities failed the check in region US-WEST-2: john@example.com',
  code: 'MessageRejected',
  time: Sat Jan 14 2017 06:11:18 GMT+0000 (UTC),
  requestId: '42f24198-da20-11e6-adbb-b3d5ae331505',
  statusCode: 400,
  retryable: false,
  retryDelay: 92.85304674413055 }

```

I played around with Pass through behaviours and that didn’t work.

> **[Serverless Framework - AWS Lambda Events - API Gateway](https://www.serverless.com/framework/docs/providers/aws/events/apigateway/)**
>
> Setting up AWS API Gateway Events with AWS Lambda via the Serverless Framework

I did also notice `template: $input.path("$.errorMessage") # JSON return object` but that example didn’t make any sense to me.

What am I missing exactly from [https://s.natalian.org/2017-01-14/serverless.yml](https://s.natalian.org/2017-01-14/serverless.yml) ?

---

<div class="post-metadata">

**Author:** ![rowanu](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/rowanu/32/75_2.png) [@rowanu](https://forum.serverless.com/u/rowanu)\
**Post date:** [January 15, 2017, 12:46am UTC](https://forum.serverless.com/t/message-internal-server-error-on-api-gateway-responses-with-1-5/1117/2 "2017-01-15T00:46:25Z")

</div>

If you want to actually return the error to the end (HTTP) user, then you don’t want to pass the error to the callback - that’s telling Lambda and API GW that the function had an error (which is why it’s telling the user 500).

It sounds like you want a _successful_ HTTP request/response, with the error details as the payload.  
So you should be using `callback(null, error)` instead of `callback(error)`.

Not sure if I’m explaining clearly, but I’m pretty sure that’s what you’re after.

---

<div class="post-metadata">

**Author:** ![hendry](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/hendry/32/343_2.png) [@hendry](https://forum.serverless.com/u/hendry)\
**Post date:** [January 15, 2017, 1:13am UTC](https://forum.serverless.com/t/message-internal-server-error-on-api-gateway-responses-with-1-5/1117/3 "2017-01-15T01:13:39Z")

</div>

Thanks for the reply!

`callback(null, error)` doesn’t work for me (HTTP/1.1 502 Bad Gateway), despite the error object having a response code set in the object IIUC!!

What did end up working was:

`callback(null, { statusCode: 400, body: JSON.stringify(error) });`

Still don’t understand… must be a bug or inconsistency I assume with the way the error object is treated.

---

<div class="post-metadata">

**Author:** ![rowanu](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/rowanu/32/75_2.png) [@rowanu](https://forum.serverless.com/u/rowanu)\
**Post date:** [January 15, 2017, 9:29am UTC](https://forum.serverless.com/t/message-internal-server-error-on-api-gateway-responses-with-1-5/1117/4 "2017-01-15T09:29:11Z")

</div>

Ah, sorry about that. I was forgetting the new Lambda proxy response types - I still often forget to stringify the payload 😖.

Glad you sorted it out.

---

<div class="post-metadata">

**Author:** ![devtanc](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/devtanc/32/611_2.png) [@devtanc](https://forum.serverless.com/u/devtanc)\
**Post date:** [April 23, 2017, 5:44am UTC](https://forum.serverless.com/t/message-internal-server-error-on-api-gateway-responses-with-1-5/1117/5 "2017-04-23T05:44:33Z")

</div>

What you’re sending back in the callback in the situation of a basic Lambda Proxy is the actual response object. You’ve got to set the `statusCode`, `headers`, and `body` as shown in the [Serverless documentation](https://serverless.com/framework/docs/providers/aws/events/apigateway#simple-http-endpoint).

`statusCode` should be a number  
`headers` is an Object with the key-value pairs as your header key-value pairs  
`body` is the response body, which needs to be `JSON.stringify`-ed by you if it’s a JSON Doc

---

<div class="post-metadata">

**Author:** ![creiglee](https://avatars.discourse-cdn.com/v4/letter/c/7ea924/32.png) [@creiglee](https://forum.serverless.com/u/creiglee)\
**Post date:** [August 9, 2017, 7:37pm UTC](https://forum.serverless.com/t/message-internal-server-error-on-api-gateway-responses-with-1-5/1117/6 "2017-08-09T19:37:08Z")

</div>

When you hit an internal [server error](http://net-informations.com/q/mis/500.html) it usually means some parts of your web server is not configured correctly or the application is trying to do something and the server is failing to carry out the request due to a conflict or restriction. This error can only be resolved by fixes to the Web server software . It is up to the administrators of the Web server site to locate and analyse the logs which should give further information about the error.

---

<div class="post-metadata">

**Author:** ![anisimovyuriy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/anisimovyuriy/32/1509_2.png) [@anisimovyuriy](https://forum.serverless.com/u/anisimovyuriy)\
**Post date:** [January 15, 2018, 11:15pm UTC](https://forum.serverless.com/t/message-internal-server-error-on-api-gateway-responses-with-1-5/1117/7 "2018-01-15T23:15:03Z")

</div>

Same here - banging my head for hours - it is still raw from documentation and implementation perspective so not synchronized… I’m wasting my time here ☹

---

<div class="post-metadata">

**Author:** ![yassermog](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/yassermog/32/2115_2.png) [@yassermog](https://forum.serverless.com/u/yassermog)\
**Post date:** [June 19, 2018, 9:56am UTC](https://forum.serverless.com/t/message-internal-server-error-on-api-gateway-responses-with-1-5/1117/8 "2018-06-19T09:56:23Z")

</div>

I relized that the problem was with  
 serverless deploy -f function\_name I just used serverless deploy -v  
and it is working now

const response = {  
statusCode: 200,  
body: JSON.stringify({  
message: Data  
}),  
};

callback(null, response);
