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:

javascript
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:

javascript
Honeybadger.notify(error, 'DescriptiveClass');

Additional Options

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

javascript
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: 'https://www.example.com/', params: { key: 'value' }, cookies: { key: 'value' } // May also be sent as a string in the document.cookie "foo=bar;bar=baz" format. });

Other Ways to Notify

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

javascript
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.