From ee49e95227d581860cf36d2c6134b226fd38334c Mon Sep 17 00:00:00 2001 From: burleyb Date: Thu, 20 Sep 2018 18:58:26 +0000 Subject: [PATCH 1/3] add ability to pass back statusCodes with errors, rather than funneling all errors through 500 --- wrappers/resource.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/wrappers/resource.js b/wrappers/resource.js index f103f1ee..cf2cae14 100644 --- a/wrappers/resource.js +++ b/wrappers/resource.js @@ -68,14 +68,21 @@ module.exports = function(configOverride, botHandler) { }); } else if (err) { console.log(err); - callback(null, { - statusCode: 500, - headers: { - 'Content-Type': config.ErrorContentType || 'text/html', - "Access-Control-Allow-Origin": config.cors ? config.cors : undefined - }, - body: err.toString() - }); + if (typeof err === "object" && "statusCode" in err) { + if (config.cors && err.headers && !("Access-Control-Allow-Origin" in err.headers)) { + err.headers["Access-Control-Allow-Origin"] = config.cors; + } + callback(null, err) + } else { + callback(null, { + statusCode: 500, + headers: { + 'Content-Type': config.ErrorContentType || 'text/html', + "Access-Control-Allow-Origin": config.cors ? config.cors : undefined + }, + body: err.toString() + }); + } } else { callback(null, { statusCode: 200, From 76bb01d691f7b92784667edb5a2fa854958cb84a Mon Sep 17 00:00:00 2001 From: burleyb Date: Mon, 28 Oct 2019 19:13:33 +0000 Subject: [PATCH 2/3] allow for passing opts into the leo.put command --- index.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 8aa676a3..841eaa8c 100644 --- a/index.js +++ b/index.js @@ -102,12 +102,17 @@ function SDK(id, data) { read: leoStream.fromLeo, write: leoStream.toLeo, - put: function(bot_id, queue, payload, callback) { - let stream = this.load(bot_id, queue, { - kinesis: { - records: 1 - } - }); + put: function(bot_id, queue, payload, opts, callback) { + if (typeof opts == "function") { + callback = opts; + opts = {}; + } + opts = Object.assign({ + kinesis: { + records: 1 + } + }, opts || {}); + let stream = this.load(bot_id, queue, opts); stream.write(payload); stream.end(callback); }, @@ -126,4 +131,4 @@ function SDK(id, data) { } }); } -module.exports = new SDK(false); \ No newline at end of file +module.exports = new SDK(false); From 16676ea9efccc3239924424bfde2f9868d66a46d Mon Sep 17 00:00:00 2001 From: Francis Lewis Date: Wed, 20 Nov 2019 15:32:41 -0700 Subject: [PATCH 3/3] Update index.js --- index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 69bfcb9e..df43f843 100644 --- a/index.js +++ b/index.js @@ -103,15 +103,15 @@ function SDK(id, data) { read: leoStream.fromLeo, write: leoStream.toLeo, put: function(bot_id, queue, payload, opts, callback) { - if (typeof opts == "function") { - callback = opts; - opts = {}; - } - opts = Object.assign({ - kinesis: { - records: 1 - } - }, opts || {}); + if (typeof opts === "function") { + callback = opts; + opts = {}; + } + opts = Object.assign({ + kinesis: { + records: 1, + }, + }, opts || {}); let stream = this.load(bot_id, queue, opts); stream.write(payload); stream.end(callback);