From b1fa8eca0abf0272d0220d37bcaefb4a66b3fffd Mon Sep 17 00:00:00 2001 From: Norwin Roosen Date: Fri, 23 Nov 2018 14:01:23 +0100 Subject: [PATCH] improve error message on compilation --- src/pages/ota-wizard/ota-wizard.ts | 6 +--- src/providers/compiler/compiler.ts | 48 +++++++++++++----------------- 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/pages/ota-wizard/ota-wizard.ts b/src/pages/ota-wizard/ota-wizard.ts index bbdf76d..2ab4087 100644 --- a/src/pages/ota-wizard/ota-wizard.ts +++ b/src/pages/ota-wizard/ota-wizard.ts @@ -156,7 +156,7 @@ export class OtaWizardPage implements OnInit, OnDestroy { private async handleUpload () { this.state.upload = 'uploading' try { - const res = await this.otaWifi.uploadFirmware(this.sketch) + const res = await this.otaWifi.uploadFirmware(this.compiledSketch) console.log(JSON.stringify(res, null, 2)) this.state.upload = 'done' @@ -169,13 +169,9 @@ export class OtaWizardPage implements OnInit, OnDestroy { } private async compileSketch () { - // TODO: implement. use this.sketch - this.state.compilation = 'compiling' try { this.compiledSketch = await this.compilerprovider.callcompiler(this.sketch) - console.log((this.compiledSketch)) - this.state.compilation = 'done' this.slides.lockSwipeToNext(false) } catch (err) { diff --git a/src/providers/compiler/compiler.ts b/src/providers/compiler/compiler.ts index f8cdcbf..ab009bb 100644 --- a/src/providers/compiler/compiler.ts +++ b/src/providers/compiler/compiler.ts @@ -1,38 +1,32 @@ import { HttpClient,HttpHeaders } from '@angular/common/http'; -import { Http, Headers, RequestOptions } from '@angular/http'; import { Injectable } from '@angular/core'; -import { BindingFlags } from '@angular/core/src/view'; -/* - Generated class for the CompilerProvider provider. - - See https://angular.io/guide/dependency-injection for more info on providers - and Angular DI. -*/ -const url = "https://compiler.sensebox.de" +const URL = "https://compiler.sensebox.de" @Injectable() export class CompilerProvider { - + constructor(public http: HttpClient) { console.log('Hello CompilerProvider Provider'); } - -async callcompiler(sketch : string): Promise { - let Headers = new HttpHeaders({'Content-Type': 'application/json'} ); - - /*let options = new RequestOptions({ headers: headers });*/ - - let data ={"board":"sensebox-mcu", "sketch":sketch} - return this.http.post(`${url}/compile`, data,{ headers:new HttpHeaders({'Content-Type': 'application/json'} ) }) - .toPromise() - .then((response:any) =>{ - console.log('API Response : ', response.data.id); - return this.http.get(`${url}/download?id=${response.data.id}&board=sensebox-mcu`,{ - responseType: 'text', + + async callcompiler(sketch : string): Promise { + const headers = new HttpHeaders({'Content-Type': 'application/json'} ); + const data = { board: 'sensebox-mcu', sketch } + + // send compilation request, returning a job ID + return this.http.post(`${URL}/compile`, data, { headers }).toPromise() + .catch(err => { + let msg = '' + try { msg = JSON.parse(err.error.message).process } catch (err) {} + throw new Error(msg || err) }) - .toPromise() - - }); + .then((response:any) =>{ + // download the resulting sketch binary + return this.http.get(`${URL}/download?id=${response.data.id}&board=sensebox-mcu`, { + responseType: 'text', + }).toPromise() + + }); }; -} \ No newline at end of file +}