org.aarboard.nextcloud.api.utils.NextcloudResponseHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nextcloud-api Show documentation
Show all versions of nextcloud-api Show documentation
Java api library to access nextcloud features from java applications
package org.aarboard.nextcloud.api.utils;
import java.util.concurrent.CompletableFuture;
import org.aarboard.nextcloud.api.exception.NextcloudApiException;
import org.aarboard.nextcloud.api.exception.NextcloudOperationFailedException;
public class NextcloudResponseHelper
{
public static final int NC_OK= 100; // Nextcloud OK message
private NextcloudResponseHelper() {
}
public static A getAndCheckStatus(CompletableFuture answer)
{
A wrappedAnswer = getAndWrapException(answer);
if(isStatusCodeOkay(wrappedAnswer))
{
return wrappedAnswer;
}
throw new NextcloudOperationFailedException(wrappedAnswer.getStatusCode(), wrappedAnswer.getMessage());
}
public static boolean isStatusCodeOkay(CompletableFuture answer)
{
return isStatusCodeOkay(getAndWrapException(answer));
}
public static boolean isStatusCodeOkay(NextcloudResponse answer)
{
return answer.getStatusCode() == NC_OK;
}
public static A getAndWrapException(CompletableFuture answer)
{
try {
return answer.get();
} catch (Exception e) {
throw new NextcloudApiException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy