Better error handling for HTTP requests. Ability to clear received AOC messages
This commit is contained in:
parent
0061859467
commit
abb267d6d3
3 changed files with 24 additions and 4 deletions
|
@ -173,6 +173,7 @@ var MessageController = {
|
|||
TypeIMessage.new("USING COST INDEX N", 1),TypeIMessage.new("WAIT FOR SYSTEM RESPONSE"),TypeIMessage.new("RWY/LS MISMATCH"),
|
||||
TypeIMessage.new("VHF3 VOICE MSG NOT GEN"),TypeIMessage.new("NO COMM MSG NOT GEN"),TypeIMessage.new("WX UPLINK"),
|
||||
TypeIMessage.new("SIMBRIEF DOWNLOAD FAILED"),TypeIMessage.new("MISSING USERNAME"),TypeIMessage.new("AOC ACT F-PLN UPLINK"),
|
||||
TypeIMessage.new("NO ANSWER TO REQUEST"),
|
||||
]),
|
||||
typeIIMessages: std.Vector.new([
|
||||
TypeIIMessage.new("LAT DISCONT AHEAD", "amb", 0),TypeIIMessage.new("MORE DRAG"),TypeIIMessage.new("RWY/LS MISMATCH", "amb", 0),TypeIIMessage.new("STEP DELETED"),
|
||||
|
|
|
@ -134,8 +134,19 @@ var receivedMessagesPage = {
|
|||
},
|
||||
leftKey: func(index) {
|
||||
if (ReceivedMessagesDatabase.getSize() >= (-5 + index + (me.curPage * 5))) {
|
||||
canvas_mcdu.myReceivedMessage[me.computer] = receivedMessagePage.new(me.computer, (-6 + index + (me.curPage * 5)));
|
||||
setprop("MCDU[" ~ me.computer ~ "]/page", "RECEIVEDMSG");
|
||||
if (mcdu_scratchpad.scratchpads[me.computer].scratchpad == "CLR") {
|
||||
ReceivedMessagesDatabase.removeAtIndex(-6 + index + (me.curPage * 5));
|
||||
me.update();
|
||||
if (ReceivedMessagesDatabase.getSize() < (me.curPage * 5)) {
|
||||
me.scrollLeft();
|
||||
}
|
||||
mcdu_scratchpad.scratchpads[me.computer].empty();
|
||||
} elsif (size(mcdu_scratchpad.scratchpads[me.computer].scratchpad) == 0) {
|
||||
canvas_mcdu.myReceivedMessage[me.computer] = receivedMessagePage.new(me.computer, (-6 + index + (me.curPage * 5)));
|
||||
setprop("MCDU[" ~ me.computer ~ "]/page", "RECEIVEDMSG");
|
||||
} else {
|
||||
mcdu_message(me.computer, "NOT ALLOWED");
|
||||
}
|
||||
} else {
|
||||
mcdu_message(me.computer, "NOT ALLOWED");
|
||||
}
|
||||
|
@ -294,6 +305,9 @@ var ReceivedMessagesDatabase = {
|
|||
getSize: func() {
|
||||
return me.database.size();
|
||||
},
|
||||
removeAtIndex: func(index) {
|
||||
return me.database.pop(index);
|
||||
},
|
||||
clearDatabase: func() {
|
||||
me.database.clear();
|
||||
},
|
||||
|
|
|
@ -148,6 +148,11 @@ var AOC = {
|
|||
}
|
||||
}
|
||||
},
|
||||
downloadFail: func(i, r = nil) {
|
||||
mcdu.mcdu_message(i,"NO ANSWER TO REQUEST");
|
||||
debug.dump("HTTP failure " ~ r.response);
|
||||
me.sent = 0;
|
||||
},
|
||||
fetchMETAR: func(airport, i) {
|
||||
if (!ATSU.working) {
|
||||
me.sent = 0;
|
||||
|
@ -169,7 +174,7 @@ var AOC = {
|
|||
}
|
||||
|
||||
http.load(serverString ~ airport)
|
||||
.fail(func(r) print("Download failed; try changing your server to NOAA"))
|
||||
.fail(func(r) me.downloadFail(i, r))
|
||||
.done(func(r) me.processMETAR(r, i));
|
||||
return 0;
|
||||
},
|
||||
|
@ -183,7 +188,7 @@ var AOC = {
|
|||
return 1;
|
||||
}
|
||||
http.load("https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=tafs&requestType=retrieve&format=xml&timeType=issue&mostRecent=true&hoursBeforeNow=12&stationString=" ~ airport)
|
||||
.fail(func print("Download failed!"))
|
||||
.fail(func(r) me.downloadFail(i))
|
||||
.done(func(r) me.processTAF(r, i));
|
||||
return 0;
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue