Skip to content

Commit

Permalink
Return correct photo ID in ms photo importer (#780)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnnorris authored Nov 7, 2019
1 parent 613bf4e commit 3555f62
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.api.client.auth.oauth2.Credential;
import com.google.common.base.Strings;
import com.google.common.base.Preconditions;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
Expand Down Expand Up @@ -192,6 +193,7 @@ private String importSinglePhoto(

try (Response response = client.newCall(requestBuilder.build()).execute()) {
int code = response.code();
ResponseBody responseBody = response.body();
if (code == 401){
// If there was an unauthorized error, then try refreshing the creds
credentialFactory.refreshCredential(credential);
Expand All @@ -200,12 +202,19 @@ private String importSinglePhoto(
requestBuilder.header("Authorization", "Bearer " + credential.getAccessToken());
Response newResponse = client.newCall(requestBuilder.build()).execute();
code = newResponse.code();
responseBody = newResponse.body();
}
if (code < 200 || code > 299) {
throw new IOException("Got error code: " + code + " message " + response.message());
}
// TODO return photo ID
return "fakeId";

// Extract photo ID from response body
Preconditions.checkState(body != null, "Got Null Body when creating photo %s", photo);
Map<String, Object> responseData = objectMapper.readValue(responseBody.bytes(), Map.class);
String photoId = (String) responseData.get("id");
checkState(!Strings.isNullOrEmpty(photoId),
"Expected id value to be present in %s", responseData);
return photoId;
}
} finally {
if (inputStream != null) {
Expand Down

0 comments on commit 3555f62

Please sign in to comment.