diff --git a/W3C.Domain/MatchmakingService/MatchmakingServiceClient.cs b/W3C.Domain/MatchmakingService/MatchmakingServiceClient.cs index 5ee0489a..4fa2eec0 100644 --- a/W3C.Domain/MatchmakingService/MatchmakingServiceClient.cs +++ b/W3C.Domain/MatchmakingService/MatchmakingServiceClient.cs @@ -100,9 +100,16 @@ public async Task> GetLiveQueueData() var response = await _httpClient.SendAsync(request); var content = await response.Content.ReadAsStringAsync(); - if (string.IsNullOrEmpty(content)) return null; - var deserializeObject = JsonConvert.DeserializeObject>(content); - return FormatQueueData(deserializeObject); // formatted for easy use on frontend + if (response.IsSuccessStatusCode) + { + if (string.IsNullOrEmpty(content)) return null; + var deserializeObject = JsonConvert.DeserializeObject>(content); + return FormatQueueData(deserializeObject); // formatted for easy use on frontend + } + else + { + throw new HttpRequestException(content, null, response.StatusCode); + } } public async Task GetMaps(GetMapsRequest request) @@ -205,13 +212,16 @@ public async Task> 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>(content); return deserializeObject; - } else { - return null; + } + else + { + throw new HttpRequestException(content, null, response.StatusCode); } } diff --git a/W3ChampionsStatisticService/Admin/AdminController.cs b/W3ChampionsStatisticService/Admin/AdminController.cs index 5dc53074..733bf911 100644 --- a/W3ChampionsStatisticService/Admin/AdminController.cs +++ b/W3ChampionsStatisticService/Admin/AdminController.cs @@ -181,8 +181,16 @@ public async Task DeleteTip(string tipId) [BearerHasPermissionFilter(Permission = EPermission.Queue)] public async Task 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")] diff --git a/W3ChampionsStatisticService/Admin/Logs/LogsController.cs b/W3ChampionsStatisticService/Admin/Logs/LogsController.cs index 3f174703..849cc27d 100644 --- a/W3ChampionsStatisticService/Admin/Logs/LogsController.cs +++ b/W3ChampionsStatisticService/Admin/Logs/LogsController.cs @@ -19,11 +19,15 @@ public class LogsController( [BearerHasPermissionFilter(Permission = EPermission.Logs)] public async Task 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); } } @@ -31,11 +35,15 @@ public async Task GetLogfileNames() [BearerHasPermissionFilter(Permission = EPermission.Logs)] public async Task 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); } } @@ -43,11 +51,15 @@ public async Task GetLogContent([FromRoute] string logfileName) [BearerHasPermissionFilter(Permission = EPermission.Logs)] public async Task 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); } } } diff --git a/W3ChampionsStatisticService/Ladder/LadderController.cs b/W3ChampionsStatisticService/Ladder/LadderController.cs index 1d409e19..01980957 100644 --- a/W3ChampionsStatisticService/Ladder/LadderController.cs +++ b/W3ChampionsStatisticService/Ladder/LadderController.cs @@ -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; @@ -90,7 +91,15 @@ public async Task GetLeagueSeasons() [HttpGet("active-modes")] public async Task 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); + } } } diff --git a/W3ChampionsStatisticService/PlayerStats/PlayerStatsController.cs b/W3ChampionsStatisticService/PlayerStats/PlayerStatsController.cs index 084f768c..b2535215 100644 --- a/W3ChampionsStatisticService/PlayerStats/PlayerStatsController.cs +++ b/W3ChampionsStatisticService/PlayerStats/PlayerStatsController.cs @@ -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; @@ -22,8 +23,16 @@ public PlayerStatsController(IPlayerStatsRepository playerRepository, PlayerStat [HttpGet("{battleTag}/race-on-map-versus-race")] public async Task 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")] diff --git a/W3ChampionsStatisticService/W3ChampionsStats/W3CStatsController.cs b/W3ChampionsStatisticService/W3ChampionsStats/W3CStatsController.cs index 3cdf9662..e3d7b7e1 100644 --- a/W3ChampionsStatisticService/W3ChampionsStats/W3CStatsController.cs +++ b/W3ChampionsStatisticService/W3ChampionsStats/W3CStatsController.cs @@ -8,6 +8,7 @@ using W3ChampionsStatisticService.W3ChampionsStats.MmrDistribution; using System.Linq; using W3C.Contracts.GameObjects; +using System.Net.Http; namespace W3ChampionsStatisticService.W3ChampionsStats; @@ -103,8 +104,16 @@ public async Task GetMmrDistribution(int season, GateWay gateWay [HttpGet("matches-on-map")] public async Task 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()