Reporting Errors

Honeybadger reports uncaught exceptions automatically. In all other cases, use Honeybadger.notify(error) to send any error to Honeybadger.

To catch an exception and notify Honeybadger without re-throwing:

try { throw('oops'); } catch(error) { Honeybadger.notify(error); }

Customizing the Error Name

JavaScript often uses generic class names -- such as Error -- which are uninformative and also cause unrelated errors to be grouped together. To get around this issue it's a good practice to send a custom error class when notifying Honeybadger:

Honeybadger.notify(error, 'DescriptiveClass');

Additional Options

You can also set or override other optional data which is reported with the error:

Honeybadger.notify(error, { message: 'My custom message', name: 'DescriptiveClass', component: 'badgers', action: 'show', context: { badgerId: 1 }, fingerprint: 'This unique string will group similar errors together', environment: 'production', projectRoot: '', params: { key: 'value' }, cookies: { key: 'value' }, // May also be sent as a string in the document.cookie "foo=bar;bar=baz" format. tags: [ 'tag-1', 'tag-2' ] });

Other Ways to Notify

You can notify Honeybadger of anything, even if you don't have an error object:

Honeybadger.notify('Badgers!'); Honeybadger.notify('Badgers!', { ... }); Honeybadger.notify('Badgers!', 'CustomClass'); Honeybadger.notify('Badgers!', 'CustomClass', { ... }); Honeybadger.notify({ message: 'Badgers!', name: 'CustomClass', ... });

A stacktrace will be generated for you (when possible) if you do not provide an error object.

Honeybadger.notify() Return Value

Honeybadger.notify() returns a boolean indicating whether the error will be reported to Honeybadger. When calling this method, some precondition checks are performed, such as checking if the client is configured or if the error is ignored based on the environment. Additionally, the beforeNotify handlers are called. If any of these checks return false, the error will not be reported and notify() will return false.

**Note: If there are any async beforeNotify handlers defined, notify() will return true by default since the result is synchronous.