Skip to content

Commit 62e1338

Browse files
committed
added notification alert
1 parent c855029 commit 62e1338

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var PrettyError = require('pretty-error');
99
var ejs = require('ejs');
1010
var sep = require('path').sep;
1111
var hljs = require('highlight.js');
12+
var notifier = require('node-notifier');
1213

1314
if (process.env.NODE_ENV === 'production') {
1415
throw new Error('dev-error-handler shouldn\'t be used in production');
@@ -74,8 +75,18 @@ module.exports = function(err, req, res, next) {
7475
// remove empty data from the array (coming from the excluded lines)
7576
lines = lines.filter(function(line) { return !!line; });
7677

78+
// pretty print in the terminal
7779
console.error((new PrettyError).render(err) || err.stack);
7880

81+
// bypass for e2e testing
82+
if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') {
83+
// send OS notification
84+
notifier.notify({
85+
title: 'Error in ' + req.method + ' ' + req.url,
86+
message: err.message
87+
});
88+
}
89+
7990
res.writeHead(500, { 'Content-Type': 'text/html' });
8091

8192
res.end(render({

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"ejs": "^2.3.4",
88
"errto": "^0.2.1",
99
"highlight.js": "https://github.com/alessioalex/highlight.js/releases/download/npm-v0.1.1/highlight.js.tar.gz.tgz",
10+
"node-notifier": "^4.4.0",
1011
"pretty-error": "^1.2.0",
1112
"stack-trace": "^0.0.9",
1213
"tiny-map-async": "^1.0.0"
@@ -27,7 +28,7 @@
2728
"errorhandler"
2829
],
2930
"scripts": {
30-
"test": "node test/test",
31+
"test": "NODE_ENV=test node test/test",
3132
"example": "node examples/http.js",
3233
"lint": "alessioalex-standard",
3334
"precommit": "npm run lint && npm test"

0 commit comments

Comments
 (0)