-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
501 additions
and
130 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
public/src/main/java/eu/solven/kumite/game/IGameMetadataConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
package eu.solven.kumite.game; | ||
|
||
public interface IGameMetadataConstants { | ||
// An optimization game consists in proposing the best solution to a given problem. They can be played independently | ||
// by any players. | ||
String TAG_OPTIMIZATION = "optimization"; | ||
|
||
// Many games are `1v1` as the oppose 2 players on a given board. | ||
String TAG_1V1 = "1v1"; | ||
|
||
// https://en.wikipedia.org/wiki/Perfect_information | ||
// https://www.reddit.com/r/boardgames/comments/bdi78u/what_are_some_simple_games_with_no_hidden/ | ||
String TAG_PERFECT_INFORMATION = "perfect_information"; | ||
|
||
// A turn-based game expects a move from a single player for any state | ||
String TAG_TURNBASED = "turned-based"; | ||
|
||
// A real-time game allows all players to move concurrently. | ||
String TAG_REALTIME = "real-time"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
server/src/main/java/eu/solven/kumite/app/webflux/KumiteWebExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package eu.solven.kumite.app.webflux; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
import org.springframework.core.annotation.Order; | ||
import org.springframework.core.io.buffer.DataBuffer; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.reactive.resource.NoResourceFoundException; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import org.springframework.web.server.WebExceptionHandler; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Component | ||
// '-2' to have higher priority than the default WebExceptionHandler | ||
@Order(-2) | ||
@Slf4j | ||
public class KumiteWebExceptionHandler implements WebExceptionHandler { | ||
|
||
@Override | ||
public Mono<Void> handle(ServerWebExchange exchange, Throwable e) { | ||
if (e instanceof NoResourceFoundException) { | ||
// Let the default WebExceptionHandler manage 404 | ||
return Mono.error(e); | ||
} else if (e instanceof IllegalArgumentException) { | ||
exchange.getResponse().setStatusCode(HttpStatus.BAD_REQUEST); | ||
} else if (e instanceof LoginRouteButNotAuthenticatedException) { | ||
exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED); | ||
} else { | ||
exchange.getResponse().setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
|
||
Map<String, Object> responseBody = new LinkedHashMap<>(); | ||
|
||
if (e.getMessage() == null) { | ||
responseBody.put("error_message", ""); | ||
} else { | ||
responseBody.put("error_message", e.getMessage()); | ||
} | ||
|
||
String respondyBodyAsString; | ||
try { | ||
respondyBodyAsString = new ObjectMapper().writeValueAsString(responseBody); | ||
} catch (JsonProcessingException ee) { | ||
log.error("Issue producing responseBody given {}", responseBody, ee); | ||
respondyBodyAsString = "{\"error_message\":\"something_went_very_wrong\"}"; | ||
} | ||
|
||
byte[] bytes = respondyBodyAsString.getBytes(StandardCharsets.UTF_8); | ||
DataBuffer buffer = exchange.getResponse().bufferFactory().wrap(bytes); | ||
return exchange.getResponse().writeWith(Flux.just(buffer)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.