catch and report parse / pack errors

This commit is contained in:
AJ ONeal 2017-10-09 15:11:32 -06:00
parent b6bc592e56
commit 4c85be0ebf
1 changed files with 18 additions and 2 deletions

View File

@ -102,12 +102,28 @@ function resolve(queryAb, opts) {
}
function resolveJson(query, opts) {
var queryAb = dnsjs.DNSPacket.write(query);
var queryAb;
try {
queryAb = dnsjs.DNSPacket.write(query);
} catch(e) {
if ('function' === typeof opts.onError) { opts.onError(e); return; }
throw e;
}
//console.log('[DEV] nameserver', opts.nameserver);
var options = {
onError: opts.onError
, onMessage: function (nb) {
var packet = dnsjs.DNSPacket.parse(nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength));
var packet;
try {
packet = dnsjs.DNSPacket.parse(nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength));
} catch(e) {
if (opts.onError) { opts.onError(e); return; }
console.error("[Error] couldn't parse incoming message");
console.error(e);
return;
}
opts.onMessage(packet);
}