From a0a020fa6c0888ffa0b60a845e70b4dfc14d14ec Mon Sep 17 00:00:00 2001 From: Chris Vaas Date: Mon, 5 Jul 2021 14:38:57 +0200 Subject: [PATCH] fix: more precise error message (#420) * fix: more precise error message * fix: tests --- index.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 0dde5f2..e4c758b 100644 --- a/index.js +++ b/index.js @@ -386,14 +386,27 @@ function _onReceive(data) { return; } - /* check message address and code + /* check message address * if we do not expect this message * raise an error */ - if (address !== transaction.nextAddress || code !== transaction.nextCode) { + if (address !== transaction.nextAddress) { error = "Unexpected data error, expected " + - transaction.nextAddress + " got " + address; - next(new Error(error)); + "address " + transaction.nextAddress + " got " + address; + if (transaction.next) + next(new Error(error)); + return; + } + + /* check message code + * if we do not expect this message + * raise an error + */ + if (code !== transaction.nextCode) { + error = "Unexpected data error, expected " + + "code " + transaction.nextCode + " got " + code; + if (transaction.next) + next(new Error(error)); return; }