From dbba59a557b1489d7175d39bdeeeb81a1932b2c9 Mon Sep 17 00:00:00 2001 From: FrenchYeti Date: Tue, 23 Feb 2021 10:26:46 +0100 Subject: [PATCH] Improve error handling --- src/DexcaliburProject.js | 12 ++++-------- src/PlatformManager.js | 2 ++ src/WebServer.js | 17 ++++++++++++----- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/DexcaliburProject.js b/src/DexcaliburProject.js index 319fdefb..ca91e169 100644 --- a/src/DexcaliburProject.js +++ b/src/DexcaliburProject.js @@ -415,20 +415,16 @@ class DexcaliburProject break; default: if(((pName instanceof Platform) === false) && (typeof pName == 'string' )){ - //if(this.device instanceof Device){ - // this.platform = this.device.getPlatform(pName); - //}else{ - this.platform = pm.getPlatform(pName); //getFromAndroidApiVersion(this.application.getMaxApiVersion()); - //} + this.platform = pm.getPlatform(pName); }else{ - this.platform = pName; - } + this.platform = pName; + } break; } // check if platform is installed if(this.platform == null){ - throw new Error("[PROJECT] synchronizePlatform : unkow platform. Aborted") + throw new Error("[PROJECT] synchronizePlatform : unknow platform. Aborted") } // install platform diff --git a/src/PlatformManager.js b/src/PlatformManager.js index 73e2eaa8..124920f0 100644 --- a/src/PlatformManager.js +++ b/src/PlatformManager.js @@ -170,6 +170,8 @@ class PlatformManager return this.remote[pName]; } + console.log("[ERROR] Platform Manager : "+pName+" is not a valid platform"); + // throw exception return null; } diff --git a/src/WebServer.js b/src/WebServer.js index 22096c8d..9672a038 100644 --- a/src/WebServer.js +++ b/src/WebServer.js @@ -395,24 +395,31 @@ class WebServer { path = device.pullTemp( req.body['path'] ); break; case 'download': - if(PLATFORM_MODE) - platform = PlatformManager.getInstance().getPlatform( req.body['platform']); path = await Downloader.downloadTemp(req.body['url'], { mode:0o666, encoding:'binary', force:true }); break; case 'upload': - platform = PlatformManager.getInstance().getPlatform( req.body['platform']); path = $.uploader.getPathOf(req.body['uploadid']); break; case 'fromfs': - platform = PlatformManager.getInstance().getPlatform( req.body['platform']); path = req.body['path']; break; } + if(platform==null){ + if(PLATFORM_MODE.indexOf(req.body['platform'])==-1){ + platform = PlatformManager.getInstance().getPlatform( req.body['platform']); + if(platform==null){ + res.status(200).send(JSON.stringify({ success:false, code:6, msg:"This platform is not installed."})); + return; + } + }else{ + platform = req.body['platform']; + } + } - // chcek if file exists an it is not empty + // check if file exists an it is not empty if( (!fs.existsSync(path)) || (false)){ res.status(200).send(JSON.stringify({ success:false, code:5, msg:"APK file not found "})); return;