From 4cfebb887f0f1f7b018e4592bae7a9055b57feab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20H=C3=A9rault?= Date: Tue, 2 Jul 2019 11:46:34 +0200 Subject: [PATCH] Fix --- src/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 4efd244fe..a77b47388 100755 --- a/src/index.js +++ b/src/index.js @@ -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]); }); @@ -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;