Skip to content

Commit

Permalink
Showing 4 changed files with 32 additions and 6 deletions.
7 changes: 1 addition & 6 deletions src/events/http/HttpServer.js
Original file line number Diff line number Diff line change
@@ -788,12 +788,6 @@ export default class HttpServer {
response.variety = 'buffer'
} else if (typeof result === 'string') {
response.source = stringify(result)
} else if (result && result.body && typeof result.body !== 'string') {
return this.#reply502(
response,
'According to the API Gateway specs, the body content must be stringified. Check your Lambda response and make sure you are invoking JSON.stringify(YOUR_CONTENT) on your body object',
{},
)
} else {
response.source = result
}
@@ -888,6 +882,7 @@ export default class HttpServer {
response.variety = 'buffer'
} else {
if (result && result.body && typeof result.body !== 'string') {
// FIXME TODO we should probably just write to console instead of returning a payload
return this.#reply502(
response,
'According to the API Gateway specs, the body content must be stringified. Check your Lambda response and make sure you are invoking JSON.stringify(YOUR_CONTENT) on your body object',
13 changes: 13 additions & 0 deletions tests/integration/lambda-integration/lambdaIntegration.test.js
Original file line number Diff line number Diff line change
@@ -28,6 +28,19 @@ describe('lambda integration tests', function desc() {
status: 200,
},

// https://github.com/dherault/serverless-offline/issues/1502
{
description: 'should return JSON',
expected: {
body: {
foo: 'bar',
},
statusCode: 200,
},
path: '/dev/lambda-integration-json-with-body',
status: 200,
},

{
description: 'should return stringified JSON',
expected: stringify({
8 changes: 8 additions & 0 deletions tests/integration/lambda-integration/serverless.yml
Original file line number Diff line number Diff line change
@@ -22,6 +22,14 @@ functions:
path: '/lambda-integration-json'
handler: src/handler.lambdaIntegrationJson

integrationJsonWithBody:
events:
- http:
integration: lambda
method: get
path: '/lambda-integration-json-with-body'
handler: src/handler.lambdaIntegrationJsonWithBody

integrationStringified:
events:
- http:
10 changes: 10 additions & 0 deletions tests/integration/lambda-integration/src/handler.js
Original file line number Diff line number Diff line change
@@ -8,6 +8,16 @@ exports.lambdaIntegrationJson = async function lambdaIntegrationJson() {
}
}

exports.lambdaIntegrationJsonWithBody =
async function lambdaIntegrationJsonWithBody() {
return {
body: {
foo: 'bar',
},
statusCode: 200,
}
}

exports.lambdaIntegrationStringified =
async function lambdaIntegrationStringified() {
return stringify({

0 comments on commit b053f57

Please sign in to comment.