All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.aarboard.nextcloud.api.utils.NextcloudResponseHelper Maven / Gradle / Ivy

There is a newer version: 13.1.0
Show newest version
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