only expose client errors in the bot/board API
parent
11b1dab2da
commit
0a930f1da0
|
@ -95,13 +95,13 @@ final class PlayApi(
|
|||
case Array("game", id, "abort") =>
|
||||
as(id, me) { pov =>
|
||||
env.bot.player.abort(pov) inject jsonOkResult recover {
|
||||
case e: lila.base.LilaException => BadRequest(e.getMessage)
|
||||
case e: lila.base.ClientError => BadRequest(e.getMessage)
|
||||
}
|
||||
}
|
||||
case Array("game", id, "resign") =>
|
||||
as(id, me) { pov =>
|
||||
env.bot.player.resign(pov) inject jsonOkResult recover {
|
||||
case e: lila.base.LilaException => BadRequest(e.getMessage)
|
||||
case e: lila.base.ClientError => BadRequest(e.getMessage)
|
||||
}
|
||||
}
|
||||
case _ => notFoundJson("No such command")
|
||||
|
|
|
@ -18,11 +18,13 @@ final class BotPlayer(
|
|||
isOfferingRematch: lila.round.IsOfferingRematch
|
||||
)(implicit ec: scala.concurrent.ExecutionContext, system: akka.actor.ActorSystem) {
|
||||
|
||||
private def clientError[A](msg: String): Fu[A] = fufail(lila.common.base.LilaException.client(msg))
|
||||
|
||||
def apply(pov: Pov, me: User, uciStr: String, offeringDraw: Option[Boolean]): Funit =
|
||||
lila.common.Future.delay((pov.game.hasAi ?? 500) millis) {
|
||||
Uci(uciStr).fold(fufail[Unit](s"Invalid UCI: $uciStr")) { uci =>
|
||||
Uci(uciStr).fold(clientError[Unit](s"Invalid UCI: $uciStr")) { uci =>
|
||||
lila.mon.bot.moves(me.username).increment()
|
||||
if (!pov.isMyTurn) fufail("Not your turn, or game already over")
|
||||
if (!pov.isMyTurn) clientError("Not your turn, or game already over")
|
||||
else {
|
||||
val promise = Promise[Unit]
|
||||
if (pov.player.isOfferingDraw && (offeringDraw contains false)) declineDraw(pov)
|
||||
|
@ -68,7 +70,7 @@ final class BotPlayer(
|
|||
}
|
||||
|
||||
def abort(pov: Pov): Funit =
|
||||
if (!pov.game.abortable) fufail("This game can no longer be aborted")
|
||||
if (!pov.game.abortable) clientError("This game can no longer be aborted")
|
||||
else
|
||||
fuccess {
|
||||
Bus.publish(
|
||||
|
@ -84,7 +86,7 @@ final class BotPlayer(
|
|||
Tell(pov.gameId, Resign(pov.playerId)),
|
||||
"roundMapTell"
|
||||
)
|
||||
} else fufail("This game cannot be resigned")
|
||||
} else clientError("This game cannot be resigned")
|
||||
|
||||
def declineDraw(pov: Pov): Unit =
|
||||
if (pov.game.drawable && pov.opponent.isOfferingDraw)
|
||||
|
|
|
@ -9,6 +9,8 @@ trait LilaException extends Exception {
|
|||
override def toString = message
|
||||
}
|
||||
|
||||
trait ClientError extends LilaException
|
||||
|
||||
object LilaException extends scalaz.syntax.ToShowOps {
|
||||
|
||||
def apply(msg: String) = new LilaException {
|
||||
|
@ -16,4 +18,8 @@ object LilaException extends scalaz.syntax.ToShowOps {
|
|||
}
|
||||
|
||||
def apply(msg: Failures): LilaException = apply(msg.shows)
|
||||
|
||||
def client(msg: String) = new ClientError {
|
||||
val message = msg
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue