1
0
Fork 0
mirror of https://github.com/sensebox/blockly-app synced 2025-12-03 14:47:55 +01:00

improve error message on compilation

This commit is contained in:
Norwin 2018-11-23 14:01:23 +01:00
parent 3c1b9d1044
commit b1fa8eca0a
2 changed files with 22 additions and 32 deletions

View file

@ -156,7 +156,7 @@ export class OtaWizardPage implements OnInit, OnDestroy {
private async handleUpload () { private async handleUpload () {
this.state.upload = 'uploading' this.state.upload = 'uploading'
try { try {
const res = await this.otaWifi.uploadFirmware(this.sketch) const res = await this.otaWifi.uploadFirmware(this.compiledSketch)
console.log(JSON.stringify(res, null, 2)) console.log(JSON.stringify(res, null, 2))
this.state.upload = 'done' this.state.upload = 'done'
@ -169,13 +169,9 @@ export class OtaWizardPage implements OnInit, OnDestroy {
} }
private async compileSketch () { private async compileSketch () {
// TODO: implement. use this.sketch
this.state.compilation = 'compiling' this.state.compilation = 'compiling'
try { try {
this.compiledSketch = await this.compilerprovider.callcompiler(this.sketch) this.compiledSketch = await this.compilerprovider.callcompiler(this.sketch)
console.log((this.compiledSketch))
this.state.compilation = 'done' this.state.compilation = 'done'
this.slides.lockSwipeToNext(false) this.slides.lockSwipeToNext(false)
} catch (err) { } catch (err) {

View file

@ -1,38 +1,32 @@
import { HttpClient,HttpHeaders } from '@angular/common/http'; import { HttpClient,HttpHeaders } from '@angular/common/http';
import { Http, Headers, RequestOptions } from '@angular/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { BindingFlags } from '@angular/core/src/view';
/* const URL = "https://compiler.sensebox.de"
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"
@Injectable() @Injectable()
export class CompilerProvider { export class CompilerProvider {
constructor(public http: HttpClient) { constructor(public http: HttpClient) {
console.log('Hello CompilerProvider Provider'); console.log('Hello CompilerProvider Provider');
} }
async callcompiler(sketch : string): Promise<any> { async callcompiler(sketch : string): Promise<any> {
let Headers = new HttpHeaders({'Content-Type': 'application/json'} ); const headers = new HttpHeaders({'Content-Type': 'application/json'} );
const data = { board: 'sensebox-mcu', sketch }
/*let options = new RequestOptions({ headers: headers });*/
// send compilation request, returning a job ID
let data ={"board":"sensebox-mcu", "sketch":sketch} return this.http.post(`${URL}/compile`, data, { headers }).toPromise()
return this.http.post(`${url}/compile`, data,{ headers:new HttpHeaders({'Content-Type': 'application/json'} ) }) .catch(err => {
.toPromise() let msg = ''
.then((response:any) =>{ try { msg = JSON.parse(err.error.message).process } catch (err) {}
console.log('API Response : ', response.data.id); throw new Error(msg || err)
return this.http.get(`${url}/download?id=${response.data.id}&board=sensebox-mcu`,{
responseType: 'text',
}) })
.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()
});
}; };
} }