1
0
Fork 0
mirror of https://github.com/sensebox/blockly-app synced 2025-10-22 17:52:18 +02:00

improved compiler error handling

This commit is contained in:
Norwin 2019-02-17 13:38:03 +01:00
parent 187b5ee561
commit c99ca318de
2 changed files with 26 additions and 16 deletions

View file

@ -8,11 +8,9 @@ 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');
}
async callcompiler(sketch : string): Promise<ArrayBuffer> { async compile(sketch : string): Promise<ArrayBuffer> {
const headers = new HttpHeaders({'Content-Type': 'application/json'} ); const headers = new HttpHeaders({'Content-Type': 'application/json'} );
const data = { board: 'sensebox-mcu', sketch } const data = { board: 'sensebox-mcu', sketch }
@ -27,10 +25,15 @@ export class CompilerProvider {
try { try {
// attempt to extract the compilation error message and clean it up // attempt to extract the compilation error message and clean it up
msg = JSON.parse(err.error.message).process console.error(err)
msg = `compilation error: ${msg.substr(msg.indexOf(' ') + 14)}` msg = JSON.parse(err.error.message)
msg = msg.substr(0, msg.indexOf('^')) if (msg.process) {
} catch (err) {} msg = `compilation error: ${msg.process.substr(msg.process.indexOf(' '))}`
msg = msg.substr(0, msg.indexOf('^'))
}
} catch (err2) {
console.error(err2)
}
throw Error(msg) throw Error(msg)
}) })
// download the resulting sketch binary // download the resulting sketch binary

View file

@ -43,14 +43,21 @@ export class OtaWifiProvider {
if (this.strategy != WifiStrategy.Automatic) if (this.strategy != WifiStrategy.Automatic)
throw new Error('can not search for WiFi networks on this platform') throw new Error('can not search for WiFi networks on this platform')
return WifiWizard2.scan() try {
.then(networks => { let networks = await WifiWizard2.scan()
if (filterSsids) if (filterSsids)
networks = networks.filter(n => n.SSID.toLowerCase().includes(SSID_PREFIX)) networks = networks.filter(n => n.SSID.toLowerCase().includes(SSID_PREFIX))
networks = networks.filter(n => n.capabilities.includes('[ESS]'))
return networks.map(n => n.SSID) return networks
}) .filter(n => n.capabilities.includes('[ESS]')) // only unencrypted networks
.map(n => n.SSID)
.filter((val, i, arr) => arr.indexOf(val) === i) // unique filter (as networks are duplicated per BSSID)
} catch (err) {
if (err === 'SCAN_FAILED')
throw new Error('WiFi scan failed. Maybe location services are disabled or the location permission isn\'t set for this app?')
else
throw new Error(err)
}
} }
async connectToSensebox (ssid: string): Promise<any> { async connectToSensebox (ssid: string): Promise<any> {
@ -59,7 +66,7 @@ export class OtaWifiProvider {
return this.platform.is('ios') return this.platform.is('ios')
? WifiWizard2.iOSConnectNetwork(ssid) ? WifiWizard2.iOSConnectNetwork(ssid)
: WifiWizard2.connect(ssid, true) : WifiWizard2.connect(ssid, true) // true: bind to all connections, even without internet
} }
async uploadFirmware (binary: ArrayBuffer): Promise<any> { async uploadFirmware (binary: ArrayBuffer): Promise<any> {