Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,19 @@ airbrake.notify(err, function(err, url) {
By default only the errors from the production environment will get reported,
so make sure to put `production` in your `NODE_ENV`.

### Severity

[Severity](https://airbrake.io/docs/airbrake-faq/what-is-severity/) allows
categorizing how severe an error is. By default, it's set to `error`. To
redefine severity, simply set an error's `severity` property. For example:

```js
var err = new Error();
err.severity = 'critical';

airbrake.notify(err);
```

### Express integration

The library provides out-of-box integration with the Express framework. It
Expand Down Expand Up @@ -200,6 +213,7 @@ each delivered error:
* **error.class:** (`err.type` string if set, or `'Error'`)
* **error.message:** (`err.message` string)
* **error.backtrace:** (`err.stack` as parsed by [stack-trace][])
* **error.severity:** (`err.severity` defaults to `error`)
* **request.url:** (`err.url`, see `airbrake.url`);
* **request.component:** (`err.component` string if set);
* **request.action:** (`err.action` string if set);
Expand Down
8 changes: 6 additions & 2 deletions lib/airbrake.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var HTTP_STATUS_CODES = require('http').STATUS_CODES;
var pkg = require('../package.json');

var fs = require('fs');
var os = require('os');
Expand All @@ -11,7 +11,10 @@ var url = require('url');

var truncator = require('../lib/truncator');

var pkg = require('../package.json');

var HTTP_STATUS_CODES = require('http').STATUS_CODES;
var DEFAULT_SEVERITY = 'error';


function Airbrake() {
this.key = null;
Expand Down Expand Up @@ -317,6 +320,7 @@ Airbrake.prototype.contextJSON = function(err) {
context.userAgent = err.ua;
context.component = err.component;
context.action = err.action;
context.severity = err.severity || DEFAULT_SEVERITY;

return context;
};
Expand Down
19 changes: 19 additions & 0 deletions test/test-severity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var common = require('./common');
var airbrake = require(common.dir.root).createClient(common.projectId, common.key);
var assert = require('assert');

(function testDefaultSeverity() {
var err = new Error();
var context = airbrake.contextJSON(err);

assert.equal(context.severity, 'error');
}());

(function testCustomSeverity() {
var customSeverity = 'critical';
var err = new Error();
err.severity = customSeverity;
var context = airbrake.contextJSON(err);

assert.equal(context.severity, customSeverity);
}());