postal.js/example/node/messaging/postal.diagnostics.js

25 lines
No EOL
622 B
JavaScript

var _ = require('underscore');
module.exports = function(postal) {
// this returns a callback that, if invoked, removes the wireTap
postal.diagnostics = postal.addWireTap(function(data, envelope) {
var all = _.extend(envelope, { data: data });
if(!JSON) {
throw "This browser or environment does not provide JSON support";
}
try {
console.log(JSON.stringify(all));
}
catch(exception) {
try {
all.data = "ERROR: " + exception.message;
console.log(JSON.stringify(all));
}
catch(ex) {
console.log("Unable to parse data to JSON: " + exception);
}
}
});
};