diff --git a/install/package.json b/install/package.json index 5989cd28e9..8580422fdf 100644 --- a/install/package.json +++ b/install/package.json @@ -194,4 +194,4 @@ "url": "https://github.com/barisusakli" } ] -} \ No newline at end of file +} diff --git a/public/src/modules/api.js b/public/src/modules/api.js index db8e0fb1b0..f510586549 100644 --- a/public/src/modules/api.js +++ b/public/src/modules/api.js @@ -7,36 +7,32 @@ import { confirm } from 'bootbox'; const baseUrl = config.relative_path + '/api/v3'; -function call(options, callback) { +async function call(options, callback) { options.url = options.url.startsWith('/api') ? config.relative_path + options.url : baseUrl + options.url; if (typeof callback === 'function') { - xhr(options, callback); + xhr(options).then(result => callback(null, result), err => callback(err)); return; } - return new Promise((resolve, reject) => { - xhr(options, function (err, data) { - if (err) { - if (err.message === 'A valid login session was not found. Please log in and try again.') { - return confirm('[[error:api.reauth-required]]', (ok) => { - if (ok) { - ajaxify.go('login'); - } - }); + try { + const result = await xhr(options); + return result; + } catch (err) { + if (err.message === 'A valid login session was not found. Please log in and try again.') { + return confirm('[[error:api.reauth-required]]', (ok) => { + if (ok) { + ajaxify.go('login'); } - - return reject(err); - } - - resolve(data); - }); - }); + }); + } + throw err; + } } -async function xhr(options, cb) { +async function xhr(options) { // Normalize body based on type const { url } = options; delete options.url; @@ -79,16 +75,14 @@ async function xhr(options, cb) { if (!res.ok) { if (response) { - return cb(new Error(isJSON ? response.status.message : response)); + throw new Error(isJSON ? response.status.message : response); } - return cb(new Error(res.statusText)); + throw new Error(res.statusText); } - cb(null, ( - isJSON && response && response.hasOwnProperty('status') && response.hasOwnProperty('response') ? - response.response : - response - )); + return isJSON && response && response.hasOwnProperty('status') && response.hasOwnProperty('response') ? + response.response : + response; } export function get(route, data, onSuccess) { diff --git a/src/cli/upgrade-plugins.js b/src/cli/upgrade-plugins.js index e789993388..2c76a6c5b1 100644 --- a/src/cli/upgrade-plugins.js +++ b/src/cli/upgrade-plugins.js @@ -106,7 +106,7 @@ async function checkPlugins() { current = plugins[suggestObj.package]; suggested = suggestObj.version; - if (suggestObj.code === 'match-found' && semver.gt(suggested, current)) { + if (suggestObj.code === 'match-found' && semver.valid(current) && semver.valid(suggested) && semver.gt(suggested, current)) { return { name: suggestObj.package, current: current,