fix: throw WrongCredentialsException in findEntry()

This commit is contained in:
Manuel Jenny 2021-03-18 17:20:09 +01:00
parent 369e1d1945
commit 80a0d7cdcd
No known key found for this signature in database
GPG Key ID: 1C80FE62B2BEAA18
2 changed files with 12 additions and 2 deletions

View File

@ -48,10 +48,13 @@ class PCloudContentRepository extends InterceptingCloudContentRepository<PCloud,
} }
private void throwWrongCredentialsExceptionIfRequired(Exception e) { private void throwWrongCredentialsExceptionIfRequired(Exception e) {
if (e instanceof ApiError && ((ApiError) e).errorCode() == PCloudApiErrorCodes.INVALID_ACCESS_TOKEN.getValue()) { if (e instanceof ApiError) {
int errorCode = ((ApiError)e).errorCode();
if (errorCode == PCloudApiErrorCodes.INVALID_ACCESS_TOKEN.getValue() || errorCode == PCloudApiErrorCodes.ACCESS_TOKEN_REVOKED.getValue()) {
throw new WrongCredentialsException(cloud); throw new WrongCredentialsException(cloud);
} }
} }
}
private static class Intercepted implements CloudContentRepository<PCloud, PCloudNode, PCloudFolder, PCloudFile> { private static class Intercepted implements CloudContentRepository<PCloud, PCloudNode, PCloudFolder, PCloudFile> {

View File

@ -20,6 +20,7 @@ import org.cryptomator.domain.exception.BackendException;
import org.cryptomator.domain.exception.CloudNodeAlreadyExistsException; import org.cryptomator.domain.exception.CloudNodeAlreadyExistsException;
import org.cryptomator.domain.exception.NoSuchCloudFileException; import org.cryptomator.domain.exception.NoSuchCloudFileException;
import org.cryptomator.domain.exception.authentication.NoAuthenticationProvidedException; import org.cryptomator.domain.exception.authentication.NoAuthenticationProvidedException;
import org.cryptomator.domain.exception.authentication.WrongCredentialsException;
import org.cryptomator.domain.usecases.ProgressAware; import org.cryptomator.domain.usecases.ProgressAware;
import org.cryptomator.domain.usecases.cloud.DataSource; import org.cryptomator.domain.usecases.cloud.DataSource;
import org.cryptomator.domain.usecases.cloud.DownloadState; import org.cryptomator.domain.usecases.cloud.DownloadState;
@ -96,6 +97,12 @@ class PCloudImpl {
} }
return Optional.empty(); return Optional.empty();
} catch(ApiError | IOException ex) { } catch(ApiError | IOException ex) {
if (ex instanceof ApiError) {
int errorCode = ((ApiError)ex).errorCode();
if (errorCode == PCloudApiErrorCodes.INVALID_ACCESS_TOKEN.getValue() || errorCode == PCloudApiErrorCodes.ACCESS_TOKEN_REVOKED.getValue()) {
throw new WrongCredentialsException(cloud);
}
}
return Optional.empty(); return Optional.empty();
} }
} }