Skip to content

Commit

Permalink
Merge pull request #318 from rollbar/add-last-error
Browse files Browse the repository at this point in the history
add back lastError on the rollbar instance
  • Loading branch information
rokob authored Jun 29, 2017
2 parents 0e945e7 + cab0eb3 commit 350af47
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ sauce_connect.log
coverage
.DS_Store
*.swp
npm-debug.log
11 changes: 11 additions & 0 deletions src/browser/rollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ Rollbar.configure = function(options) {
}
};

Rollbar.prototype.lastError = function() {
return this.client.lastError;
};
Rollbar.lastError = function() {
if (_instance) {
return _instance.lastError();
} else {
handleUninitialized();
}
};

Rollbar.prototype.log = function() {
var item = this._createItem(arguments);
var uuid = item.uuid;
Expand Down
12 changes: 12 additions & 0 deletions src/rollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function Rollbar(options, api, logger, platform) {
Rollbar.rateLimiter.setPlatformOptions(platform, options);
this.queue = new Queue(Rollbar.rateLimiter, api, logger, this.options);
this.notifier = new Notifier(this.queue, this.options);
this.lastError = null;
}

var defaultOptions = {
Expand Down Expand Up @@ -73,6 +74,9 @@ Rollbar.prototype.wait = function(callback) {
/* Internal */

Rollbar.prototype._log = function(defaultLevel, item) {
if (this._sameAsLastError(item)) {
return;
}
_.wrapRollbarFunction(this.logger, function() {
var callback = null;
if (item.callback) {
Expand All @@ -88,4 +92,12 @@ Rollbar.prototype._defaultLogLevel = function() {
return this.options.logLevel || 'debug';
};

Rollbar.prototype._sameAsLastError = function(item) {
if (this.lastError && this.lastError === item.err) {
return true;
}
this.lastError = item.err;
return false;
};

module.exports = Rollbar;
11 changes: 11 additions & 0 deletions src/server/rollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ Rollbar.configure = function(options) {
}
};

Rollbar.prototype.lastError = function() {
return this.client.lastError;
};
Rollbar.lastError = function() {
if (_instance) {
return _instance.lastError();
} else {
handleUninitialized();
}
};

Rollbar.prototype.log = function() {
var item = this._createItem(arguments);
var uuid = item.uuid;
Expand Down
3 changes: 3 additions & 0 deletions test/server.rollbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function TestClientGen() {
this.logCalls.push({func: fn, item: item});
}.bind(this, fn)
}
this.clearLogCalls = function() {
this.logCalls = [];
};
};

return TestClient;
Expand Down

0 comments on commit 350af47

Please sign in to comment.