diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-11-20 06:01:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-11-20 06:19:39 +0000 |
commit | 56eec1de7018759c0ec251dba4455c18f73c3bbd (patch) | |
tree | 3aeb2d10356530bc2cc3f24e74f41048a13885b4 /src/zerror.js | |
parent | Initial commit. (diff) | |
download | zmodemjs-upstream/0.1.10+dfsg.tar.xz zmodemjs-upstream/0.1.10+dfsg.zip |
Adding upstream version 0.1.10+dfsg.upstream/0.1.10+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/zerror.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/zerror.js b/src/zerror.js new file mode 100644 index 0000000..1a779de --- /dev/null +++ b/src/zerror.js @@ -0,0 +1,47 @@ +"use strict"; + +var Zmodem = module.exports; + +function _crc_message(got, expected) { + this.got = got.slice(0); + this.expected = expected.slice(0); + return "CRC check failed! (got: " + got.join() + "; expected: " + expected.join() + ")"; +} + +function _pass(val) { return val } + +const TYPE_MESSAGE = { + aborted: "Session aborted", + peer_aborted: "Peer aborted session", + already_aborted: "Session already aborted", + crc: _crc_message, + validation: _pass, +}; + +function _generate_message(type) { + const msg = TYPE_MESSAGE[type]; + switch (typeof msg) { + case "string": + return msg; + case "function": + var args_after_type = [].slice.call(arguments).slice(1); + return msg.apply(this, args_after_type); + } + + return null; +} + +Zmodem.Error = class ZmodemError extends Error { + constructor(msg_or_type) { + super(); + + var generated = _generate_message.apply(this, arguments); + if (generated) { + this.type = msg_or_type; + this.message = generated; + } + else { + this.message = msg_or_type; + } + } +}; |