Reject if the distribution json is invalid, displaying the error overlay instead of looping.

This commit is contained in:
TheFlash787 2020-08-12 12:32:32 +01:00
parent 46853157ec
commit 86647eb53a

View File

@ -546,11 +546,11 @@ exports.pullRemote = function(){
const distroDest = path.join(ConfigManager.getLauncherDirectory(), 'distribution.json') const distroDest = path.join(ConfigManager.getLauncherDirectory(), 'distribution.json')
request(opts, (error, resp, body) => { request(opts, (error, resp, body) => {
if(!error){ if(!error){
try { try {
data = DistroIndex.fromJSON(JSON.parse(body)) data = DistroIndex.fromJSON(JSON.parse(body))
} catch (e) { resolve(data)
reject(e) } catch(e) {
reject('We cannot parse the JSON in the remote distribution file')
} }
fs.writeFile(distroDest, body, 'utf-8', (err) => { fs.writeFile(distroDest, body, 'utf-8', (err) => {
@ -574,8 +574,12 @@ exports.pullLocal = function(){
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
fs.readFile(DEV_MODE ? DEV_PATH : DISTRO_PATH, 'utf-8', (err, d) => { fs.readFile(DEV_MODE ? DEV_PATH : DISTRO_PATH, 'utf-8', (err, d) => {
if(!err){ if(!err){
try {
data = DistroIndex.fromJSON(JSON.parse(d)) data = DistroIndex.fromJSON(JSON.parse(d))
resolve(data) resolve(data)
} catch(e) {
reject('We cannot parse the JSON in the local distribution file')
}
} else { } else {
reject(err) reject(err)
} }