From a3742e4564f56a68f8e49551c0abfbddcc81ad45 Mon Sep 17 00:00:00 2001 From: Raccoon Date: Sun, 17 May 2020 03:25:20 +0800 Subject: [PATCH 1/2] fix: getStatus should reject promise 1. reject promise when getStatus failed 2. change to use promise-way call getStatus in debug message Signed-off-by: Raccoon --- lib/realtime/realtime.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/realtime/realtime.js b/lib/realtime/realtime.js index 6fce654f..f8c7ade3 100644 --- a/lib/realtime/realtime.js +++ b/lib/realtime/realtime.js @@ -298,10 +298,12 @@ function getStatus () { } }) .catch(function (err) { - return logger.error('count user failed: ' + err) + logger.error('count user failed: ' + err) + return Promise.reject(new Error('count user failed: ' + err)) }) }).catch(function (err) { - return logger.error('count note failed: ' + err) + logger.error('count note failed: ' + err) + return Promise.reject(new Error('count note failed: ' + err)) }) } @@ -772,8 +774,7 @@ function queueForConnect (socket) { const noteId = socket.noteId logger.info('SERVER connected a client to [' + noteId + ']:') logger.info(JSON.stringify(user)) - // logger.info(notes); - getStatus(function (data) { + getStatus().then(function (data) { logger.info(JSON.stringify(data)) }) } From ac6021a57990d17b4a218ace0fad50130fd1bfb2 Mon Sep 17 00:00:00 2001 From: Raccoon Date: Sun, 17 May 2020 03:25:57 +0800 Subject: [PATCH 2/2] fix: returning 500 when getStatus failed Signed-off-by: Raccoon --- lib/status/index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/status/index.js b/lib/status/index.js index 56c92ec0..2f5366d6 100644 --- a/lib/status/index.js +++ b/lib/status/index.js @@ -4,14 +4,19 @@ const realtime = require('../realtime/realtime') const config = require('../config') exports.getStatus = async (req, res) => { - const data = await realtime.getStatus() - res.set({ 'Cache-Control': 'private', // only cache by client 'X-Robots-Tag': 'noindex, nofollow', // prevent crawling 'Content-Type': 'application/json' }) - res.send(data) + + try { + const data = await realtime.getStatus() + res.send(data) + } catch (e) { + console.error(e) + res.status(500).send(e.toString()) + } } exports.getMetrics = async (req, res) => {