1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-26 20:54:22 +01:00

better error handling on uploading

This commit is contained in:
Federico Fissore 2013-05-28 17:46:15 +02:00
parent c174737584
commit 556c6ea5c1
2 changed files with 42 additions and 36 deletions

View File

@ -1680,11 +1680,14 @@ public class Sketch {
Preferences.set(uploader.getAuthorizationKey(), DigestUtils.sha256Hex(dialog.getPassword())); Preferences.set(uploader.getAuthorizationKey(), DigestUtils.sha256Hex(dialog.getPassword()));
} }
success = uploader.uploadUsingPreferences(buildPath, suggestedClassName, usingProgrammer); try {
success = uploader.uploadUsingPreferences(buildPath, suggestedClassName, usingProgrammer);
if (uploader.requiresAuthorization() && !success) { } finally {
Preferences.remove(uploader.getAuthorizationKey()); if (uploader.requiresAuthorization() && !success) {
Preferences.remove(uploader.getAuthorizationKey());
}
} }
} while (uploader.requiresAuthorization() && !success); } while (uploader.requiresAuthorization() && !success);
return success; return success;

View File

@ -155,14 +155,17 @@ public class HttpUploader extends Uploader {
} }
} }
protected boolean boardNotReady(String auth) { protected boolean boardNotReady(String auth) throws RunnerException {
GetMethod get = new GetMethod(baseUrl + "/ready"); GetMethod get = new GetMethod(baseUrl + "/ready");
get.setRequestHeader("Authorization", "Basic " + auth); get.setRequestHeader("Authorization", "Basic " + auth);
try { try {
int httpStatus = client.executeMethod(get); int httpStatus = client.executeMethod(get);
if (httpStatus % HttpStatus.SC_BAD_REQUEST < 100 || httpStatus % HttpStatus.SC_INTERNAL_SERVER_ERROR < 100) {
System.err.println(get.getResponseBodyAsString());
throw new RunnerException("Problem knowing if the board was ready");
}
return httpStatus != HttpStatus.SC_OK; return httpStatus != HttpStatus.SC_OK;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace();
return true; return true;
} }
} }