diff --git a/src/lib/app.ts b/src/lib/app.ts
index 6de9ec9fc41e..7f52e49b74f3 100644
--- a/src/lib/app.ts
+++ b/src/lib/app.ts
@@ -197,12 +197,6 @@ export default async function getApp(
         services.openApiService.useErrorHandler(app);
     }
 
-    if (process.env.NODE_ENV !== 'production') {
-        app.use(errorHandler());
-    } else {
-        app.use(catchAllErrorHandler(config.getLogger));
-    }
-
     app.get(`${baseUriPath}`, (req, res) => {
         res.set('Content-Type', 'text/html');
         res.send(indexHTML);
@@ -229,5 +223,11 @@ export default async function getApp(
         res.send(indexHTML);
     });
 
+    if (process.env.NODE_ENV !== 'production') {
+        app.use(errorHandler());
+    } else {
+        app.use(catchAllErrorHandler(config.getLogger));
+    }
+
     return app;
 }