]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server.ts
refactor API errors to standard error format
[github/Chocobozzz/PeerTube.git] / server.ts
index 97dffe7567e6a9758ca61f1c81dd4f83374248aa..1834256d5f936d64d076383615493c59cb13a26c 100644 (file)
--- a/server.ts
+++ b/server.ts
@@ -127,6 +127,8 @@ import { PluginManager } from './server/lib/plugins/plugin-manager'
 import { LiveManager } from './server/lib/live-manager'
 import { HttpStatusCode } from './shared/core-utils/miscs/http-error-codes'
 import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache'
+import { ServerConfigManager } from '@server/lib/server-config-manager'
+import { apiResponseHelpers } from '@server/helpers/express-utils'
 
 // ----------- Command line -----------
 
@@ -185,6 +187,9 @@ app.use(cookieParser())
 // W3C DNT Tracking Status
 app.use(advertiseDoNotTrack)
 
+// Response helpers used in developement
+app.use(apiResponseHelpers)
+
 // ----------- Views, routes and static files -----------
 
 // API
@@ -234,7 +239,11 @@ app.use(function (err, req, res, next) {
   const sql = err.parent ? err.parent.sql : undefined
 
   logger.error('Error in controller.', { err: error, sql })
-  return res.status(err.status || HttpStatusCode.INTERNAL_SERVER_ERROR_500).end()
+  return res.fail({
+    status: err.status || HttpStatusCode.INTERNAL_SERVER_ERROR_500,
+    message: err.message,
+    type: err.name
+  })
 })
 
 const server = createWebsocketTrackerServer(app)
@@ -262,7 +271,8 @@ async function startApplication () {
 
   await Promise.all([
     Emailer.Instance.checkConnection(),
-    JobQueue.Instance.init()
+    JobQueue.Instance.init(),
+    ServerConfigManager.Instance.init()
   ])
 
   // Caches initializations