Skip to content

Commit

Permalink
Do not cache mm error. Add error handling for some mm calls (#347)
Browse files Browse the repository at this point in the history
* do not cache GetActiveGameModes call if mm does not respond with game modes

* more error handling for failed mm calls

* error handling for queue data and logs
  • Loading branch information
gustav87 authored Oct 11, 2024
1 parent 39ff878 commit ada2d1c
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 25 deletions.
24 changes: 17 additions & 7 deletions W3C.Domain/MatchmakingService/MatchmakingServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,16 @@ public async Task<List<MappedQueue>> GetLiveQueueData()
var response = await _httpClient.SendAsync(request);

var content = await response.Content.ReadAsStringAsync();
if (string.IsNullOrEmpty(content)) return null;
var deserializeObject = JsonConvert.DeserializeObject<List<Queue>>(content);
return FormatQueueData(deserializeObject); // formatted for easy use on frontend
if (response.IsSuccessStatusCode)
{
if (string.IsNullOrEmpty(content)) return null;
var deserializeObject = JsonConvert.DeserializeObject<List<Queue>>(content);
return FormatQueueData(deserializeObject); // formatted for easy use on frontend
}
else
{
throw new HttpRequestException(content, null, response.StatusCode);
}
}

public async Task<GetMapsResponse> GetMaps(GetMapsRequest request)
Expand Down Expand Up @@ -205,13 +212,16 @@ public async Task<List<ActiveGameMode>> GetCurrentlyActiveGameModes() {
request.Headers.Add("x-admin-secret", AdminSecret);
var response = await _httpClient.SendAsync(request);

if (response.IsSuccessStatusCode) {
var content = await response.Content.ReadAsStringAsync();
var content = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
if (string.IsNullOrEmpty(content)) return null;
var deserializeObject = JsonConvert.DeserializeObject<List<ActiveGameMode>>(content);
return deserializeObject;
} else {
return null;
}
else
{
throw new HttpRequestException(content, null, response.StatusCode);
}
}

Expand Down
12 changes: 10 additions & 2 deletions W3ChampionsStatisticService/Admin/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,16 @@ public async Task<IActionResult> DeleteTip(string tipId)
[BearerHasPermissionFilter(Permission = EPermission.Queue)]
public async Task<IActionResult> GetQueueData()
{
var queueData = await _matchmakingServiceRepository.GetLiveQueueData();
return Ok(queueData);
try
{
var queueData = await _matchmakingServiceRepository.GetLiveQueueData();
return Ok(queueData);
}
catch (HttpRequestException ex)
{
int statusCode = ex.StatusCode is null ? 500 : (int)ex.StatusCode;
return StatusCode(statusCode, ex.Message);
}
}

[HttpGet("proxies")]
Expand Down
30 changes: 21 additions & 9 deletions W3ChampionsStatisticService/Admin/Logs/LogsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,47 @@ public class LogsController(
[BearerHasPermissionFilter(Permission = EPermission.Logs)]
public async Task<IActionResult> GetLogfileNames()
{
try {
try
{
var logfileNames = await _logsRepository.GetLogfileNames();
return Ok(logfileNames);
} catch (HttpRequestException ex) {
return StatusCode((int)ex.StatusCode, ex.Message);
}
catch (HttpRequestException ex)
{
int statusCode = ex.StatusCode is null ? 500 : (int)ex.StatusCode;
return StatusCode(statusCode, ex.Message);
}
}

[HttpGet("{logfileName}")]
[BearerHasPermissionFilter(Permission = EPermission.Logs)]
public async Task<IActionResult> GetLogContent([FromRoute] string logfileName)
{
try {
try
{
var logContent = await _logsRepository.GetLogContent(logfileName);
return Ok(logContent);
} catch (HttpRequestException ex) {
return StatusCode((int)ex.StatusCode, ex.Message);
}
catch (HttpRequestException ex)
{
int statusCode = ex.StatusCode is null ? 500 : (int)ex.StatusCode;
return StatusCode(statusCode, ex.Message);
}
}

[HttpGet("download/{logfileName}")]
[BearerHasPermissionFilter(Permission = EPermission.Logs)]
public async Task<IActionResult> DownloadLog([FromRoute] string logfileName)
{
try {
try
{
var content = await _logsRepository.DownloadLog(logfileName);
return File(content, MediaTypeNames.Text.Plain, logfileName);
} catch (HttpRequestException ex) {
return StatusCode((int)ex.StatusCode, ex.Message);
}
catch (HttpRequestException ex)
{
int statusCode = ex.StatusCode is null ? 500 : (int)ex.StatusCode;
return StatusCode(statusCode, ex.Message);
}
}
}
13 changes: 11 additions & 2 deletions W3ChampionsStatisticService/Ladder/LadderController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using W3C.Contracts.Matchmaking;
using W3ChampionsStatisticService.Ports;
Expand Down Expand Up @@ -90,7 +91,15 @@ public async Task<IActionResult> GetLeagueSeasons()
[HttpGet("active-modes")]
public async Task<IActionResult> GetActiveGameModes()
{
var currentlyActiveModes = await _matchmakingProvider.GetCurrentlyActiveGameModesAsync();
return Ok(currentlyActiveModes);
try
{
var currentlyActiveModes = await _matchmakingProvider.GetCurrentlyActiveGameModesAsync();
return Ok(currentlyActiveModes);
}
catch (HttpRequestException ex)
{
int statusCode = ex.StatusCode is null ? 500 : (int)ex.StatusCode;
return StatusCode(statusCode, ex.Message);
}
}
}
15 changes: 12 additions & 3 deletions W3ChampionsStatisticService/PlayerStats/PlayerStatsController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using W3ChampionsStatisticService.PlayerStats.HeroStats;
using W3ChampionsStatisticService.Ports;
Expand All @@ -22,8 +23,16 @@ public PlayerStatsController(IPlayerStatsRepository playerRepository, PlayerStat
[HttpGet("{battleTag}/race-on-map-versus-race")]
public async Task<IActionResult> GetRaceOnMapVersusRaceStat([FromRoute] string battleTag, int season)
{
var stats = await _playerStatisticsService.GetMapAndRaceStatAsync(battleTag, season);
return Ok(stats);
try
{
var stats = await _playerStatisticsService.GetMapAndRaceStatAsync(battleTag, season);
return Ok(stats);
}
catch (HttpRequestException ex)
{
int statusCode = ex.StatusCode is null ? 500 : (int)ex.StatusCode;
return StatusCode(statusCode, ex.Message);
}
}

[HttpGet("{battleTag}/hero-on-map-versus-race")]
Expand Down
13 changes: 11 additions & 2 deletions W3ChampionsStatisticService/W3ChampionsStats/W3CStatsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using W3ChampionsStatisticService.W3ChampionsStats.MmrDistribution;
using System.Linq;
using W3C.Contracts.GameObjects;
using System.Net.Http;

namespace W3ChampionsStatisticService.W3ChampionsStats;

Expand Down Expand Up @@ -103,8 +104,16 @@ public async Task<IActionResult> GetMmrDistribution(int season, GateWay gateWay
[HttpGet("matches-on-map")]
public async Task<IActionResult> GetMatchesOnMap()
{
var mmrs = await _statisticsService.LoadMatchesOnMapAsync();
return Ok(mmrs);
try
{
var mmrs = await _statisticsService.LoadMatchesOnMapAsync();
return Ok(mmrs);
}
catch (HttpRequestException ex)
{
int statusCode = ex.StatusCode is null ? 500 : (int)ex.StatusCode;
return StatusCode(statusCode, ex.Message);
}
}

private DateTimeOffset GetDefaultMinDateOffset()
Expand Down

0 comments on commit ada2d1c

Please sign in to comment.