ソースを参照

custom errorlogging middleware

Andi Dittrich 4 年 前
コミット
75ee05e2ea
1 ファイル変更8 行追加0 行削除
  1. 8 0
      examples/express.js

+ 8 - 0
examples/express.js

@@ -29,6 +29,14 @@ async function bootstrap(){
         throw new Error('Server Error');
     });
 
+    // custom errorhandling middleware
+    // use this pattern in production to log errors!
+    _webapp.use(function(err, req, res, next){
+        console.log(`[custom logging middleware] ${err.message}`);
+        // forward error
+        next(err);
+    });
+
     // use http error pages handler (final statement!)
     // because of the asynchronous file-loaders, wait until it has been executed
     await _httpErrorPages.express(_webapp, {