Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow calling Bugsnag.notify() with no arguments #197

Merged
merged 4 commits into from Oct 6, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/bugsnag.js
Expand Up @@ -76,6 +76,9 @@
// will not see it in your dashboard.
self.notifyException = function (exception, name, metaData, severity) {
if (!exception) {
var message = "Bugsnag.notifyException() was called with no arguments";
log(message);
self.notify("UnspecifiedBugsnagError", message);
return;
}

Expand Down Expand Up @@ -115,6 +118,12 @@
// Notify Bugsnag about an error by passing in a `name` and `message`,
// without requiring an exception.
self.notify = function (name, message, metaData, severity) {
if (!name) {
name = "UnspecifiedBugsnagError";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth pulling this to the top of the file where we declare some other constant-esque variables?

message = "Bugsnag.notify() was called with no arguments";
log(message);
}

sendToBugsnag({
name: name,
message: message,
Expand Down
14 changes: 14 additions & 0 deletions test/test.bugsnag.js
Expand Up @@ -109,6 +109,12 @@ describe("Bugsnag", function () {
assert.equal(requestData().params.name, "CustomError");
});

it("should add custom class when no exception is given", function () {
Bugsnag.notifyException();

assert.equal(requestData().params.name, "UnspecifiedBugsnagError");
});

it("should contain the correct exception message", function () {
Bugsnag.notifyException(new Error("Example error"));

Expand Down Expand Up @@ -367,6 +373,14 @@ describe("Bugsnag", function () {
assert.equal(requestData().params.name, "CustomError");
});


it("should create an error name when none is provided", function () {
Bugsnag.notify();

assert.equal(requestData().params.name, "UnspecifiedBugsnagError");
});


it("should contain 'warning' as the default severity", function () {
Bugsnag.notify("CustomError", "Something broke");

Expand Down