Skip to content
This repository was archived by the owner on Aug 8, 2024. It is now read-only.

Commit 770324a

Browse files
author
ujann
committed
also error strings have to be json-stringified
1 parent ac5126e commit 770324a

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/proxyIntegration.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ function normalizeRequestPath(event) {
8080

8181
function convertError(error, errorMapping, headers) {
8282
if (typeof error.reason === 'string' && errorMapping && errorMapping[error.reason]) {
83-
return {statusCode: errorMapping[error.reason], body: error.message, headers: headers};
83+
return {statusCode: errorMapping[error.reason], body: JSON.stringify(error.message), headers: headers};
8484
}else if(typeof error.status === 'number'){
85-
return {statusCode: error.status, body: error.message, headers: addCorsHeaders({})};
85+
return {statusCode: error.status, body: JSON.stringify(error.message), headers: addCorsHeaders({})};
8686
}
8787
try{
8888
return {statusCode: 500, body: `Generic error: ${JSON.stringify(error)}`, headers: addCorsHeaders({})};

test/proxyIntegration.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ describe('proxyIntegration.routeHandler', () => {
306306
proxyIntegration(routeConfig, {path: '/', httpMethod: 'GET'}).then(result => {
307307
expect(result).toEqual({
308308
statusCode: 501,
309-
body: 'bla',
309+
body: '"bla"',
310310
headers: Object.assign({"Content-Type": "application/json"}, expectedCorsHeaders)
311311
});
312312
done();
@@ -350,7 +350,7 @@ describe('proxyIntegration.routeHandler', () => {
350350
proxyIntegration(routeConfig, {path: '/', httpMethod: 'GET'}).then(result => {
351351
expect(result).toEqual({
352352
statusCode: 666,
353-
body: {reason: 'oops'},
353+
body: '{"reason":"oops"}',
354354
headers: expectedCorsHeaders
355355
});
356356
done();
@@ -384,7 +384,7 @@ describe('proxyIntegration.routeHandler.returnvalues', () => {
384384
proxyIntegration(routeConfig, {path: '/', httpMethod: 'GET'}).then(result => {
385385
expect(result).toEqual({
386386
statusCode: 599,
387-
body: 'doof',
387+
body: '"doof"',
388388
headers: {"Content-Type": "application/json"}
389389
});
390390
done();

0 commit comments

Comments
 (0)