mirror of
https://github.com/sensebox/blockly-app
synced 2025-10-21 08:03:54 +02:00
improved compiler error handling
This commit is contained in:
parent
187b5ee561
commit
c99ca318de
2 changed files with 26 additions and 16 deletions
|
@ -8,11 +8,9 @@ const URL = "https://compiler.sensebox.de"
|
|||
@Injectable()
|
||||
export class CompilerProvider {
|
||||
|
||||
constructor(public http: HttpClient) {
|
||||
console.log('Hello CompilerProvider Provider');
|
||||
}
|
||||
constructor(public http: HttpClient) { }
|
||||
|
||||
async callcompiler(sketch : string): Promise<ArrayBuffer> {
|
||||
async compile(sketch : string): Promise<ArrayBuffer> {
|
||||
const headers = new HttpHeaders({'Content-Type': 'application/json'} );
|
||||
const data = { board: 'sensebox-mcu', sketch }
|
||||
|
||||
|
@ -27,10 +25,15 @@ export class CompilerProvider {
|
|||
|
||||
try {
|
||||
// attempt to extract the compilation error message and clean it up
|
||||
msg = JSON.parse(err.error.message).process
|
||||
msg = `compilation error: ${msg.substr(msg.indexOf(' ') + 14)}`
|
||||
msg = msg.substr(0, msg.indexOf('^'))
|
||||
} catch (err) {}
|
||||
console.error(err)
|
||||
msg = JSON.parse(err.error.message)
|
||||
if (msg.process) {
|
||||
msg = `compilation error: ${msg.process.substr(msg.process.indexOf(' '))}`
|
||||
msg = msg.substr(0, msg.indexOf('^'))
|
||||
}
|
||||
} catch (err2) {
|
||||
console.error(err2)
|
||||
}
|
||||
throw Error(msg)
|
||||
})
|
||||
// download the resulting sketch binary
|
||||
|
|
|
@ -43,14 +43,21 @@ export class OtaWifiProvider {
|
|||
if (this.strategy != WifiStrategy.Automatic)
|
||||
throw new Error('can not search for WiFi networks on this platform')
|
||||
|
||||
return WifiWizard2.scan()
|
||||
.then(networks => {
|
||||
if (filterSsids)
|
||||
networks = networks.filter(n => n.SSID.toLowerCase().includes(SSID_PREFIX))
|
||||
networks = networks.filter(n => n.capabilities.includes('[ESS]'))
|
||||
try {
|
||||
let networks = await WifiWizard2.scan()
|
||||
if (filterSsids)
|
||||
networks = networks.filter(n => n.SSID.toLowerCase().includes(SSID_PREFIX))
|
||||
|
||||
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> {
|
||||
|
@ -59,7 +66,7 @@ export class OtaWifiProvider {
|
|||
|
||||
return this.platform.is('ios')
|
||||
? 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> {
|
||||
|
|
Loading…
Add table
Reference in a new issue