You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -72,42 +72,44 @@ stackify.log('error', {error : new Error()});
72
72
When logging an error message you could pass an Error object in metadata like in the last case so the exception details would be available.
73
73
74
74
#### Exception handling
75
-
Supported frameworks
76
-
Express (ver 4.x) and all express-based frameworks only (e.g. SailsJS, Connect, LocomotiveJS) will be supported. This means all of the frameworks that support the format of the middleware functions used in Express.JS.
77
-
function (req, res, next) {
78
-
//some code
79
-
next();
80
-
}
75
+
By executing stackify.start() you set handler for uncaught exceptions.
76
+
Be sure to run it before any methods that set exception handlers.
81
77
82
78
##### Using with pure NodeJS app
83
-
If you are not using any of the frameworks and all requests are handled inside native createServer method you should run stackify.exceptionHandler() first line inside of this method :
79
+
If you are not using any of the frameworks and all requests are handled inside native `createServer()` method and you want to get web details of exception to be sent with it you should run stackify.exceptionHandler(req) first line inside of this method :
84
80
85
81
```js
86
82
var http =require('http');
87
83
var stackify =require('stackify-logger');
88
84
http.createServer(function (req, res) {
89
-
stackify.stats(req, res);
85
+
stackify.exceptionHandler(req);
90
86
res.setHeader('content-type', 'text/plain');
91
87
res.end('hello');
92
88
});
93
89
});
94
90
```
91
+
where req is request object, instance of `http.IncomingMessage`
95
92
96
93
You can use it also with any framework that doesn’t modify native createServer method.
97
94
98
95
99
96
##### Using with Express
100
-
It acts as middleware when running on express-based apps. Since middleware are execute serially, their order of inclusion is important.
101
-
102
-
You can activate it with the app.use() command in the appropriate place of your code, e.g.:
97
+
Global handler doesn't work inside Express route methods.
98
+
You should use error-handling middleware function `stackify.expressExceptionHandler`. Since middleware is executed serially, it's order of inclusion is important. Be sure to add it before any other error-handling middleware.
103
99
104
100
```js
105
101
var express =require('express');
106
102
var app =express();
107
-
app.use(stackify.expressExceptionHandler());
103
+
104
+
/*
105
+
*** block of route handlers ***
106
+
*** *** **** **** **** **** ***
107
+
*/
108
+
109
+
app.use(stackify.expressExceptionHandler);
108
110
```
109
111
110
-
To handle exceptions correctly put this right after all route handlers and before all the other error middleware.
112
+
To handle exceptions correctly put this right after all route handlers.
0 commit comments