From 91291327b02e5b9468b4697714c1a03481939ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6lsche?= Date: Thu, 14 Oct 2021 10:31:53 +0200 Subject: [PATCH] Fix get after close --- index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 4cff7b2..8be6665 100644 --- a/index.js +++ b/index.js @@ -82,6 +82,11 @@ exports.init = function (sbot, config) { } if(conf.hook !== false) + var closed = false + sbot.close.hook(function (fn, args) { + closed = true + return fn.apply(this, args) + }) sbot.get.hook(function (fn, args) { var id = args[0] var cb = args[1] @@ -90,9 +95,13 @@ exports.init = function (sbot, config) { if(id.ooo === false && isMsg(id.id)) fn(id, cb) else fn(id, function (err, value) { - if(!err) cb(null, value) - else get(id, function (_err, data) { - if(_err) fn(id, cb) //just in-case, try the log again + if(!err) return cb(null, value) + if (closed) return cb(err) + get(id, function (_err, data) { + if(_err) { + if (!closed) fn(id, cb) //just in-case, try the log again + else cb(_err) + } else cb(null, id.meta === true ? data : data.value) }) })