Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding future-proof error message matcher for upload hash validation #1155

Merged
merged 4 commits into from
Sep 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
public class GooglePhotosInterface {

public static final String ERROR_HASH_MISMATCH = "Hash mismatch";
private static final String GOOG_ERROR_HASH_MISMATCH_LEGACY = "Checksum from header does not match received payload content.";
private static final String GOOG_ERROR_HASH_MISMATCH_UNIFIED = "User-provided checksum does not match received payload content.";

private static final String BASE_URL = "https://photoslibrary.googleapis.com/v1/";
private static final int ALBUM_PAGE_SIZE = 20; // TODO
Expand Down Expand Up @@ -260,9 +262,12 @@ <T> T makePostRequest(String url, Optional<Map<String, String>> parameters,
* Note that making this a separate method to avoid polluting throw lists.
*/
private void maybeRethrowAsUploadError(HttpResponseException e) throws UploadErrorException {
if (e.getStatusCode() == 400 && e.getContent()
.contains("Checksum from header does not match received payload content.")) {
throw new UploadErrorException(ERROR_HASH_MISMATCH, e);
if (e.getStatusCode() == 400) {
if (e.getContent().contains(GOOG_ERROR_HASH_MISMATCH_LEGACY) || e.getContent()
.contains(GOOG_ERROR_HASH_MISMATCH_UNIFIED)) {
throw new UploadErrorException(ERROR_HASH_MISMATCH, e);
}
// Delegate other 400 errors and non-400 errors to {@link #handleHttpResponseException}.
}
}

Expand Down