-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (26 loc) · 795 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var path = require('path');
var statuses = require('statuses');
var notifier = require('node-notifier');
var successIcon = path.join(__dirname, 'icons/success.png');
var errorIcon = path.join(__dirname, 'icons/error.png');
module.exports = function (opts) {
opts = opts || {};
return function* (next) {
try {
yield* next;
} catch (e) {
var status = e.status || e.code || e.statusCode || 500;
notifier.notify(opts[status] || {
title: status,
message: e.message || statuses[status],
icon: errorIcon
});
throw e;
}
notifier.notify(opts[this.status] || {
title: this.status,
message: this.body || this.message || statuses[this.status],
icon: (this.status < 400) ? successIcon : errorIcon
});
};
};