Permalink
Browse files

Closes #1: Disable window.onerror handling by default.

  • Loading branch information...
1 parent 7261fa1 commit a6fb18368e4044442662994cab3c913913cd85f5 @joshuap joshuap committed Mar 13, 2013
Showing with 69 additions and 41 deletions.
  1. +17 −0 README.md
  2. +3 −1 coffee/src/honeybadger.coffee
  3. +15 −6 coffee/test/honeybadger.spec.coffee
  4. +33 −33 honeybadger.min.js
  5. +1 −1 honeybadger.min.js.map
View
@@ -55,6 +55,9 @@ frameworks like Backbone and Ember.
// Action (optional)
action: ''
+ // Should unhandled (window.onerror) notifications be sent?
+ onerror: false
+
// Disable notifications?
disabled: false
});
@@ -98,6 +101,20 @@ merged locally:
// Honeybadger.context == { user_id: 1 }
+## Unhandled errors via (window.onerror)
+
+By default, honeybadger-js does not track unhandled errors. This is
+because `window.onerror` is a very limited method of error handling, and
+does not usually yield useful information. It is our official
+recommendation to always use try/catch explicitly to notify Honeybadger.
+If you still want to automatically catch errors via `window.onerror`,
+you can set the `onerror` configuration option to true:
+
+ Honeybadger.configure({
+ api_key: 'your public api key',
+ onerror: true
+ });
+
## Contributing
1. Fork it.
@@ -14,6 +14,7 @@ class Honeybadger
component: null
action: null
disabled: true
+ onerror: false
@configured: false
@@ -85,7 +86,8 @@ class Honeybadger
form.submit()
@_handleTraceKitSubscription: (stackInfo) =>
- @notify(null, { stackInfo: stackInfo })
+ if @configuration.onerror
+ @notify(null, { stackInfo: stackInfo })
TraceKit.report.subscribe Honeybadger._handleTraceKitSubscription
@@ -108,13 +108,22 @@ describe 'Honeybadger', ->
expect(Honeybadger._sendRequest).not.toHaveBeenCalled()
describe '._handleTraceKitSubscription', ->
- it 'notifies Honeybadger of unhandled exceptions', ->
+ beforeEach () ->
spyOn Honeybadger, 'notify'
- Honeybadger.configure
- api_key: 'asdf'
+ describe 'default behavior', ->
+ it 'ignores unhandled errors', ->
+ Honeybadger._handleTraceKitSubscription({})
+ expect(Honeybadger.notify).not.toHaveBeenCalled()
+
+ describe 'when onerror is enabled', ->
+ beforeEach () ->
+ Honeybadger.configure
+ api_key: 'asdf',
+ onerror: true
- stackInfo = 'foo'
- Honeybadger._handleTraceKitSubscription(stackInfo)
+ it 'notifies Honeybadger of unhandled exceptions', ->
+ stackInfo = 'foo'
+ Honeybadger._handleTraceKitSubscription(stackInfo)
- expect(Honeybadger.notify).toHaveBeenCalledWith(null, { stackInfo: stackInfo })
+ expect(Honeybadger.notify).toHaveBeenCalledWith(null, { stackInfo: stackInfo })
Oops, something went wrong.

0 comments on commit a6fb183

Please sign in to comment.