airbrake-mini-client
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "airbrake-mini-client", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A lightweight alternative to airbrake-js.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -54,3 +54,22 @@ # airbrake-mini-client | ||
### Airbrake payload example: | ||
### Filters | ||
You can use this feature to avoid sending an error to the server if it matches some criteria. You can also use this function to enrich the notice with specific informations. You can add as many filters you want. The method is chainable. | ||
```js | ||
airbrakeMini.addFilter((notice) => { | ||
// if I return null, the notice gets discarded | ||
// I can also mutate the notice to add some data | ||
}) | ||
``` | ||
Here's some example: | ||
```js | ||
airbrakeMini | ||
.addFilter((notice) => { | ||
const { context } = notice | ||
if (context.url && context.url.indexOf('file') === 0) { | ||
return null | ||
} | ||
}) | ||
``` | ||
### Airbrake notice example: | ||
```json | ||
@@ -76,5 +95,5 @@ { | ||
"notifier": { | ||
"name": "airbrake-js", | ||
"version": "1.4.3", | ||
"url": "https://github.com/airbrake/airbrake-js" | ||
"name": "airbrake-mini-client", | ||
"version": "0.0.3", | ||
"url": "https://github.com/tes/airbrake-mini-client" | ||
} | ||
@@ -81,0 +100,0 @@ }, |
@@ -10,5 +10,6 @@ var objectAssign = require('object-assign') | ||
this.reporter = config.reporter || new Reporter(config) | ||
this.filters = [] | ||
} | ||
AirbrakeMini.prototype.notify = function notify (err) { | ||
AirbrakeMini.prototype.notify = function airbrakeMiniNotify (err) { | ||
var payload = { | ||
@@ -34,5 +35,21 @@ id: '', | ||
} | ||
this.reporter.notify(payload) | ||
var filteredPayload = this._filter(payload) | ||
if (filteredPayload) { | ||
this.reporter.notify(filteredPayload) | ||
} | ||
} | ||
AirbrakeMini.prototype._filter = function _airbrakeFilter (payload) { | ||
for (var i = 0; i < this.filters.length; i++) { | ||
payload = this.filters[i](payload) | ||
if (!payload) break | ||
} | ||
return payload | ||
} | ||
AirbrakeMini.prototype.addFilter = function airbrakeMiniAddFilter (func) { | ||
this.filters.push(func) | ||
return this | ||
} | ||
module.exports = AirbrakeMini |
@@ -39,2 +39,26 @@ /* eslint-env browser, mocha */ | ||
}) | ||
it('filters out', () => { | ||
airbrake.addFilter(function (notice) { // passthrough | ||
if (notice.context.severity === 'error') return null | ||
return notice | ||
}) | ||
airbrake.addFilter(function (notice) { // filter out | ||
if (notice.context.severity === 'warning') return null | ||
return notice | ||
}) | ||
airbrake.notify({ error: new Error('BOOM!'), context: { severity: 'warning' } }) | ||
assert.isFalse(reporter.notify.calledOnce) | ||
}) | ||
it('add data', () => { | ||
airbrake.addFilter(function (notice) { | ||
return Object.assign({}, notice, { id: 1 }) | ||
}) | ||
airbrake.notify({ error: new Error('BOOM!'), context: { severity: 'warning' } }) | ||
assert.isTrue(reporter.notify.calledOnce) | ||
var payload = reporter.notify.args[0][0] | ||
assert.equal(payload.id, 1) | ||
assert.deepEqual(payload.context, { severity: 'warning', windowError: false, history: [] }) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14259
350
103