Skip to content

Commit

Permalink
Throw invalid token exception for video import (#1222)
Browse files Browse the repository at this point in the history
* Throw invalid token exception for video import

Summary: Capture and throw invalid token exception for video import

Test Plan: ./gradlew test

---------

Co-authored-by: Srujith Mallidi <[email protected]>
  • Loading branch information
srujithm and Srujith Mallidi authored Mar 24, 2023
1 parent dfa7c2e commit 44a52ce
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
package org.datatransferproject.datatransfer.google.videos;

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.api.gax.rpc.ApiException;
import com.google.api.gax.rpc.InvalidArgumentException;
import com.google.api.gax.rpc.UnauthenticatedException;
import com.google.auth.oauth2.AccessToken;
Expand Down Expand Up @@ -325,6 +326,14 @@ private Pair<String, Long> uploadMediaItem(UUID jobId, VideoModel inputVideo,
uploadToken = uploadResponse.getUploadToken().get();
}
return Pair.of(uploadToken, tmp.length());
} catch (ApiException ex) {
// temp check as exception is not captured and wrapped into UploadMediaItemResponse
Throwable cause = ex.getCause();
String message = cause.getMessage();
if (message.contains("invalid_grant")) {
throw new InvalidTokenException("Token has been expired or revoked", cause);
}
throw new IOException("An error was encountered while uploading the video.", cause);
} finally {
//noinspection ResultOfMethodCallIgnored
tmp.delete();
Expand Down

0 comments on commit 44a52ce

Please sign in to comment.