Skip to content

Commit

Permalink
fix: more precise error message (#420)
Browse files Browse the repository at this point in the history
* fix: more precise error message

* fix: tests
  • Loading branch information
Chris Vaas authored Jul 5, 2021
1 parent ea7ea76 commit a0a020f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit a0a020f

Please sign in to comment.