File tree Expand file tree Collapse file tree 4 files changed +19
-7
lines changed Expand file tree Collapse file tree 4 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -54,11 +54,14 @@ module.exports = function (app, db) {
54
54
// We provide a simple GET /session in order to get session information directly.
55
55
// This is used by the browser application (Angular) to determine if a user is
56
56
// logged in already.
57
- app . get ( '/session' , function ( req , res ) {
57
+ app . get ( '/session' , function ( req , res , next ) {
58
+ var err ;
58
59
if ( req . user ) {
59
60
res . send ( { user : req . user . sanitize ( ) } ) ;
60
61
} else {
61
- res . status ( 401 ) . send ( 'No authenticated user.' ) ;
62
+ err = new Error ( 'No authenticated user.' ) ;
63
+ err . status = 401 ;
64
+ next ( err ) ;
62
65
}
63
66
} ) ;
64
67
Original file line number Diff line number Diff line change @@ -22,10 +22,14 @@ module.exports = function (db) {
22
22
*/
23
23
app . use ( function ( req , res , next ) {
24
24
25
+ var err ;
26
+
25
27
if ( path . extname ( req . path ) . length > 0 ) {
26
- res . status ( 404 ) . end ( ) ;
28
+ err = new Error ( 'Not found.' ) ;
29
+ err . status = 404 ;
30
+ next ( err ) ;
27
31
} else {
28
- next ( null ) ;
32
+ next ( ) ;
29
33
}
30
34
31
35
} ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ router.use('/members', require('./members'));
6
6
7
7
// Make sure this is after all of
8
8
// the registered routes!
9
- router . use ( function ( req , res ) {
10
- res . status ( 404 ) . end ( ) ;
9
+ router . use ( function ( req , res , next ) {
10
+ var err = new Error ( 'Not found.' ) ;
11
+ err . status = 404 ;
12
+ next ( err ) ;
11
13
} ) ;
Original file line number Diff line number Diff line change @@ -4,10 +4,13 @@ module.exports = router;
4
4
var _ = require ( 'lodash' ) ;
5
5
6
6
var ensureAuthenticated = function ( req , res , next ) {
7
+ var err ;
7
8
if ( req . isAuthenticated ( ) ) {
8
9
next ( ) ;
9
10
} else {
10
- res . status ( 401 ) . end ( ) ;
11
+ err = new Error ( 'You must be logged in.' ) ;
12
+ err . status = 401 ;
13
+ next ( err ) ;
11
14
}
12
15
} ;
13
16
You can’t perform that action at this time.
0 commit comments