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()));
}
try {
success = uploader.uploadUsingPreferences(buildPath, suggestedClassName, usingProgrammer);
} finally {
if (uploader.requiresAuthorization() && !success) {
Preferences.remove(uploader.getAuthorizationKey());
}
}
} while (uploader.requiresAuthorization() && !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");
get.setRequestHeader("Authorization", "Basic " + auth);
try {
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;
} catch (IOException e) {
e.printStackTrace();
return true;
}
}