Permalink
Browse files

Send plain text "errors" as a Message instead of a real error, fixes #18

  • Loading branch information...
1 parent 718f5e3 commit acccbfdcdac098ce9504a36c0c040780b1c7564a @mattrobenolt mattrobenolt committed Sep 29, 2012
Showing with 21 additions and 0 deletions.
  1. +9 −0 lib/client.js
  2. +12 −0 test/raven.client.js
View
@@ -101,6 +101,15 @@ _.captureMessage = function captureMessage(message, kwargs, cb) {
_.captureError =
_.captureException = function captureError(err, kwargs, cb) {
+ if(!(err instanceof Error)) {
+ // This handles when someone does:
+ // throw "something awesome";
+ // We just send the "Error" as a normal message
+ // since there is no way to compute a stack trace
+ // See: https://github.com/mattrobenolt/raven-node/issues/18
+ return this.captureMessage('Error: ' + err, kwargs, cb);
+ }
+
var self = this;
if(!cb && typeof kwargs === 'function') {
cb = kwargs;
View
@@ -165,6 +165,18 @@ describe('raven.Client', function(){
client.captureError(new Error('wtf?'));
});
+ it('should send a plain text "error" as a Message instead', function(done){
+ // See: https://github.com/mattrobenolt/raven-node/issues/18
+ var old = client.captureMessage;
+ client.captureMessage = function(message) {
+ // I'm also appending "Error: " to the beginning to help hint
+ message.should.equal('Error: wtf?');
+ done();
+ client.captureMessage = old;
+ };
+ client.captureError('wtf?');
+ });
+
it('should send an Error to Sentry server on another port', function(done){
var scope = nock('https://app.getsentry.com:8443')
.filteringRequestBody(/.*/, '*')

0 comments on commit acccbfd

Please sign in to comment.