浏览代码

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, {