feat(versionCheck): add timeout to 1s and change logger type to avoid log error to disturb user

Signed-off-by: BoHong Li <raccoon@hackmd.io>
This commit is contained in:
BoHong Li 2020-03-17 01:24:38 +08:00
parent 4c7497960a
commit b49a4e24f1
No known key found for this signature in database
GPG Key ID: 06770355DC9ECD38

View File

@ -30,11 +30,12 @@ async function checkVersion (ctx) {
const { statusCode, body: data } = await rp({
url: `${VERSION_CHECK_ENDPOINT}?v=${config.version}`,
method: 'GET',
json: true
json: true,
timeout: 1000
})
if (statusCode !== 200 || data.status === 'error') {
logger.error('Version check failed.')
logger.warn('Version check failed.')
return
}
@ -46,12 +47,12 @@ async function checkVersion (ctx) {
if (!data.latest) {
const { version, link } = data.versionItem
logger.warn(`Your CodiMD version is out of date! The latest version is ${version}. Please see what's new on ${link}.`)
logger.info(`Your CodiMD version is out of date! The latest version is ${version}. Please see what's new on ${link}.`)
}
} catch (err) {
// ignore and skip version check
logger.error('Version check failed.')
logger.error(err)
logger.warn('Version check failed.')
logger.warn(err)
}
}