package pro.beam.api.util;

import com.google.common.base.Function;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import org.apache.http.client.HttpResponseException;
import pro.beam.api.exceptions.BeamException;
import pro.beam.api.exceptions.tetris.MissingGameException;
import pro.beam.api.resource.tetris.RobotInfo;

public class Tetris {
    private static final int GAME_UNSET_CODE = 404;

    public static CheckedFuture<RobotInfo, BeamException> checkFutureRobotInfo(ListenableFuture<RobotInfo> future) {
        return Futures.makeChecked(future, TETRIS_EXCEPTION_TRANSFORMER);
    }

    private static final Function<Exception, BeamException> TETRIS_EXCEPTION_TRANSFORMER = new Function<Exception, BeamException>() {
        @Override public BeamException apply(Exception e) {
            Throwable cause = e.getCause();
            if (!(cause instanceof HttpResponseException)) {
                return null;
            }

            HttpResponseException hre = (HttpResponseException) cause;
            int status = hre.getStatusCode();

            if (status == GAME_UNSET_CODE) {
                return new MissingGameException();
            }

            return null;
        }
    };
}

@@ -504,17 +504,17 @@
 ODE = 40
-4
+3
 ;%0A%0A    p

Update to latest unset game response code