Skip to content

Commit

Permalink
Throw 404 instead of 500 if no leaderboard entry could be found.
Browse files Browse the repository at this point in the history
This happens regularly if the leaderboard record is inactive.
Fixes #371, also fixes #302
  • Loading branch information
Brutus5000 committed Dec 18, 2019
1 parent 0209d61 commit 5f57f4d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 28 deletions.
1 change: 1 addition & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.faforever.api.leaderboard;

import com.faforever.api.web.ResourceNotFoundException;
import com.faforever.api.error.Error;
import com.faforever.api.error.ErrorCode;
import com.faforever.api.error.NotFoundApiException;
import com.google.common.collect.ImmutableMap;
import com.yahoo.elide.jsonapi.models.Data;
import com.yahoo.elide.jsonapi.models.JsonApiDocument;
Expand Down Expand Up @@ -76,13 +78,13 @@ public CompletableFuture<JsonApiDocument> getGlobal(@RequestParam(value = "page[
@Async
@RequestMapping(path = "/ladder1v1/{playerId}", method = RequestMethod.GET)
@ApiOperation("Lists the ladder1v1 leaderboard for the specified player")
public CompletableFuture<JsonApiDocument> getSingleLadder1v1(@PathVariable("playerId") String playerId) {
Ladder1v1LeaderboardEntry entry = leaderboardService.getLadder1v1Entry(Integer.valueOf(playerId));
public CompletableFuture<JsonApiDocument> getSingleLadder1v1(@PathVariable("playerId") Integer playerId) {
Ladder1v1LeaderboardEntry entry = leaderboardService.getLadder1v1Entry(playerId);
if (entry == null) {
throw new ResourceNotFoundException("No ladder1v1 entry found for player: " + playerId);
throw new NotFoundApiException(new Error(ErrorCode.ENTITY_NOT_FOUND, playerId));
}

Resource resource = new Resource(LADDER_1V1_LEADERBOARD_ENTRY, playerId, ImmutableMap.<String, Object>builder()
Resource resource = new Resource(LADDER_1V1_LEADERBOARD_ENTRY, playerId.toString(), ImmutableMap.<String, Object>builder()
.put("name", entry.getPlayerName())
.put("mean", entry.getMean())
.put("deviation", entry.getDeviation())
Expand All @@ -99,13 +101,13 @@ public CompletableFuture<JsonApiDocument> getSingleLadder1v1(@PathVariable("play
@Async
@RequestMapping(path = "/global/{playerId}", method = RequestMethod.GET)
@ApiOperation("Lists the global leaderboard for the specified player")
public CompletableFuture<JsonApiDocument> getSingleGlobal(@PathVariable("playerId") String playerId) {
GlobalLeaderboardEntry entry = leaderboardService.getGlobalEntry(Integer.valueOf(playerId));
public CompletableFuture<JsonApiDocument> getSingleGlobal(@PathVariable("playerId") Integer playerId) {
GlobalLeaderboardEntry entry = leaderboardService.getGlobalEntry(playerId);
if (entry == null) {
throw new ResourceNotFoundException("No global leaderboard entry found for player: " + playerId);
throw new NotFoundApiException(new Error(ErrorCode.ENTITY_NOT_FOUND, playerId));
}

Resource resource = new Resource(GLOBAL_LEADERBOARD_ENTRY, playerId, ImmutableMap.<String, Object>builder()
Resource resource = new Resource(GLOBAL_LEADERBOARD_ENTRY, playerId.toString(), ImmutableMap.<String, Object>builder()
.put("name", entry.getPlayerName())
.put("mean", entry.getMean())
.put("deviation", entry.getDeviation())
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/com/faforever/api/web/ResourceNotFoundException.java

This file was deleted.

0 comments on commit 5f57f4d

Please sign in to comment.