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

org.johnnei.enjin.internal.ResponseWrapper Maven / Gradle / Ivy

The newest version!
package org.johnnei.enjin.internal;

import java.util.Optional;

public class ResponseWrapper extends EnjinWrapper {

	private Optional result;

	private ResponseError error;

	ResponseWrapper() {
		// Used by GSON
	}

	public ResponseWrapper(T result, ResponseError error) {
		this.result = Optional.ofNullable(result);
		this.error = error;
	}

	public boolean isInErrorState() {
		return error != null;
	}

	public EnjinError getError() {
		if (error == null) {
			throw new IllegalStateException("Response is not in error state.");
		}

		return error.getError();
	}

	public T getResponse() {
		return result.orElseThrow(() -> new IllegalStateException("Response is in error state."));
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy