Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dherault committed Jul 2, 2019
1 parent bea8ccd commit 4cfebb8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/index.js
Expand Up @@ -925,15 +925,15 @@ class Offline {

/* LAMBDA PROXY INTEGRATION HAPIJS RESPONSE CONFIGURATION */

response.statusCode = statusCode = result.statusCode || 200;
response.statusCode = statusCode = (result || {}).statusCode || 200;

const headers = {};
if (result.headers) {
if (result && result.headers) {
Object.keys(result.headers).forEach(header => {
headers[header] = (headers[header] || []).concat(result.headers[header]);
});
}
if (result.multiValueHeaders) {
if (result && result.multiValueHeaders) {
Object.keys(result.multiValueHeaders).forEach(header => {
headers[header] = (headers[header] || []).concat(result.multiValueHeaders[header]);
});
Expand All @@ -960,14 +960,14 @@ class Offline {

response.header('Content-Type', 'application/json', { override: false, duplicate: false });

if (typeof result.body !== 'undefined') {
if (result && typeof result.body !== 'undefined') {
if (result.isBase64Encoded) {
response.encoding = 'binary';
response.source = Buffer.from(result.body, 'base64');
response.variety = 'buffer';
}
else {
if (result.body && typeof result.body !== 'string') {
if (result && result.body && typeof result.body !== 'string') {
return this._reply500(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', {});
}
response.source = result.body;
Expand Down

0 comments on commit 4cfebb8

Please sign in to comment.