Explorar o código

custom errorlogging middleware

Andi Dittrich %!s(int64=4) %!d(string=hai) anos
pai
achega
75ee05e2ea
Modificáronse 1 ficheiros con 8 adicións e 0 borrados
  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, {