Skip to content

Commit

Permalink
Merge pull request #57 from MindscapeHQ/add-option-for-human-string
Browse files Browse the repository at this point in the history
Add option to turn off human-readable-string conversion
  • Loading branch information
dwnz committed Jan 27, 2016
2 parents f5fb744 + 880baf9 commit b20a61c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)

Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/raygun.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion lib/raygun.messageBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
23 changes: 22 additions & 1 deletion test/raygun.messageBuilder_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down

0 comments on commit b20a61c

Please sign in to comment.