Skip to content

Commit

Permalink
Catch JSON parse errors
Browse files Browse the repository at this point in the history
Yield a `null` value message, add the parse error to the `deliveryInfo` as `parseError`, also expose `rawData` containing the parsed data.
  • Loading branch information
novemberborn committed Nov 7, 2011
1 parent 988a469 commit 9a05b7e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion amqp.js
Expand Up @@ -1492,7 +1492,13 @@ Queue.prototype.subscribe = function (/* options, messageListener */) {
m.addListener('end', function () {
var json, deliveryInfo = {}, msgProperties = classes[60].fields;
if (isJSON) {
json = JSON.parse(b);
try {
json = JSON.parse(b);
} catch (e) {
json = null;
deliveryInfo.parseError = e;
deliveryInfo.rawData = b;
}
} else {
json = { data: b, contentType: m.contentType };
}
Expand Down

0 comments on commit 9a05b7e

Please sign in to comment.