Add error.type2str

This commit is contained in:
Kagami Hiiragi 2015-02-21 20:17:12 +03:00
parent 3f57b972d7
commit 0642977538
2 changed files with 16 additions and 0 deletions

View File

@ -452,6 +452,20 @@ var error = exports.error = {
*/ */
FATAL: 2, FATAL: 2,
/**
* Convert error type to a human-readable string.
* @param {number} fatal - Type of the error
* @return {string}
*/
type2str: function(fatal) {
switch (fatal) {
case error.WARNING: return "warning";
case error.ERROR: return "error";
case error.FATAL: return "fatal";
default: return "unknown";
}
},
/** /**
* @typedef {Object} DecodeResult * @typedef {Object} DecodeResult
* @property {number} fatal - Type of the error * @property {number} fatal - Type of the error

View File

@ -596,6 +596,7 @@ describe("Message types", function() {
expect(res.vector).to.not.exist; expect(res.vector).to.not.exist;
expect(res.errorText).to.equal("test"); expect(res.errorText).to.equal("test");
expect(res.length).to.equal(8); expect(res.length).to.equal(8);
expect(error.type2str(res.fatal)).to.equal("warning");
var vector = inv_vect.encode(Buffer("test")); var vector = inv_vect.encode(Buffer("test"));
var res = error.decode(error.encode({ var res = error.decode(error.encode({
@ -609,6 +610,7 @@ describe("Message types", function() {
expect(bufferEqual(res.vector, vector)).to.be.true; expect(bufferEqual(res.vector, vector)).to.be.true;
expect(res.errorText).to.equal("fatal error"); expect(res.errorText).to.equal("fatal error");
expect(res.length).to.equal(47); expect(res.length).to.equal(47);
expect(error.type2str(res.fatal)).to.equal("fatal");
}); });
}); });
}); });