Esempio n. 1
0
func (this *RespondWith) UnexpectedError(err api.Error) {
	if err.Any() {
		this.Error(http.StatusInternalServerError, err)
		return
	}

	this.Error(http.StatusInternalServerError, api.UserError("An unexpected error happened."))
}
Esempio n. 2
0
func (this PlayersController) Authenticate(ginContext *gin.Context) {
	_, err := models.Player{}.Find(this.Context.AeContext, this.Context.AccessToken)

	if err.Any() {
		this.RespondWith.Error(http.StatusForbidden, api.UserError("Invalid Access Token"))
		ginContext.Abort()
	}
}
Esempio n. 3
0
func (this Game) Guess(c appengine.Context, player *Player, p api.M) api.Error {
	game, err := this.Find(c, p["id"], player)

	if err.Any() {
		return err
	}

	if game.IsOver() {
		return api.UserError("Game ended wit status: " + this.Status)
	}

	if !game.ValidGuess(p["guess"]) {
		return api.UserError("Sorry, try guessing one lowercase letter per time.")
	}

	game.GuessALetter(p["guess"])

	_, error := datastore.Put(c, keyFromId(c, p["id"], player), game)

	return api.DevError(error)
}