diff --git a/README.md b/README.md index 41103be..5faa577 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,17 @@ When initializing Raygun, pass through a `groupingKey` function. } }); +### Custom error objects + +By default Raygun4Node tries to convert unknown objects into a human readable string to help with grouping, this doens't always make sense. + +To disable it + + var raygunClient = new raygun.Client().init({ + apiKey: 'YOUR_KEY', + useHumanStringForObject: false + }); + ### Examples View a screencast on creating an app with Node.js and Express.js, then hooking up the error handling and sending them at [http://raygun.io/blog/2013/07/video-nodejs-error-handling-with-raygun/](http://raygun.io/blog/2013/07/video-nodejs-error-handling-with-raygun/) @@ -223,6 +234,7 @@ In lieu of a formal styleguide, take care to maintain the existing coding style. ## Release History +- 0.8.5 - Add ability to turn off 'humanised-object-strings' - 0.8.4 - Add some smarts around passing an object in to the exception parameter - 0.8.3 - Turn strings into errors if passed through. Log out request errors. - 0.8.2 - Add setTags method diff --git a/lib/raygun.js b/lib/raygun.js index 520a135..5c151b9 100644 --- a/lib/raygun.js +++ b/lib/raygun.js @@ -15,7 +15,7 @@ var MessageBuilder = require('./raygun.messageBuilder'); var OfflineStorage = require('./raygun.offline'); var Raygun = function () { - var _apiKey, _filters, raygun = this, _user, _version, _host, _port, _useSSL, _onBeforeSend, _offlineStorage, _isOffline, _offlineStorageOptions, _groupingKey, _tags; + var _apiKey, _filters, raygun = this, _user, _version, _host, _port, _useSSL, _onBeforeSend, _offlineStorage, _isOffline, _offlineStorageOptions, _groupingKey, _tags, _useHumanStringForObject; raygun.init = function (options) { _apiKey = options.apiKey; @@ -29,6 +29,7 @@ var Raygun = function () { _isOffline = options.isOffline; _groupingKey = options.groupingKey; _tags = options.tags; + _useHumanStringForObject = options.useHumanStringForObject === undefined ? true : options.useHumanStringForObject; if (_isOffline) { _offlineStorage.init(_offlineStorageOptions); @@ -88,7 +89,7 @@ var Raygun = function () { mergedTags = mergedTags.concat(tags); } - var builder = new MessageBuilder({filters: _filters}) + var builder = new MessageBuilder({filters: _filters, useHumanStringForObject: _useHumanStringForObject}) .setErrorDetails(exception) .setRequestDetails(request) .setMachineName() diff --git a/lib/raygun.messageBuilder.js b/lib/raygun.messageBuilder.js index e0c98a1..6e30615 100644 --- a/lib/raygun.messageBuilder.js +++ b/lib/raygun.messageBuilder.js @@ -52,7 +52,7 @@ var RaygunMessageBuilder = function (options) { this.setErrorDetails = function (error) { var errorType = Object.prototype.toString.call(error); - if (errorType === '[object Object]') { + if (errorType === '[object Object]' && options.useHumanStringForObject) { error = humanString(error); message.details.groupingKey = error.replace(/\W+/g, "").substring(0, 64); } diff --git a/package.json b/package.json index a11f2df..b22b489 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "raygun", "description": "Raygun.io plugin for Node", - "version": "0.8.4", + "version": "0.8.5", "homepage": "https://github.com/MindscapeHQ/raygun4node", "author": { "name": "MindscapeHQ", diff --git a/test/raygun.messageBuilder_test.js b/test/raygun.messageBuilder_test.js index 03cfdb1..1a9a286 100644 --- a/test/raygun.messageBuilder_test.js +++ b/test/raygun.messageBuilder_test.js @@ -45,7 +45,28 @@ test('basic builder tests', function (t) { tt.ok(message.details.machineName); tt.end(); }); - + + t.test('humanise error string', function (tt){ + var builder = new MessageBuilder({ useHumanStringForObject:true }); + builder.setErrorDetails({name:'Test'}); + + var message = builder.build(); + tt.ok(message.details.error.message); + tt.equal('name=Test', message.details.error.message); + tt.ok(message.details.groupingKey); + tt.end(); + }); + + t.test('dont humanise string', function (tt){ + var builder = new MessageBuilder({useHumanStringForObject:false}); + builder.setErrorDetails({name:'Test'}); + + var message = builder.build(); + tt.notOk(message.details.groupingKey); + tt.equal('NoMessage', message.details.error.message); + tt.end(); + }); + t.end(); });