mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-23 19:30:06 +02:00
feature: Server error provider added, client notification service added
This commit is contained in:
1 parent
3c67595d94
commit
b928e0fec9
14 files changed
+200
-11
No files matched your search
@@ -1,6 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using StrawberryShake;
|
||||
using WotBlitzStatisticsPro.Blazor.GraphQl;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Blazor.Services
|
||||
@@ -8,10 +10,14 @@ namespace WotBlitzStatisticsPro.Blazor.Services
|
||||
public class GraphQlBackendService: IGraphQlBackendService
|
||||
{
|
||||
private readonly WotBlitzStatisticsProClient _client;
|
||||
private readonly INotificationsService _notificationsService;
|
||||
|
||||
public GraphQlBackendService(WotBlitzStatisticsProClient client)
|
||||
public GraphQlBackendService(
|
||||
WotBlitzStatisticsProClient client,
|
||||
INotificationsService notificationsService)
|
||||
{
|
||||
_client = client;
|
||||
_notificationsService = notificationsService;
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<IFindPlayers_Players>?> FindPlayers(string accountNick, RealmType realmType)
|
||||
@@ -19,6 +25,7 @@ namespace WotBlitzStatisticsPro.Blazor.Services
|
||||
var accounts =
|
||||
await _client.FindPlayers.ExecuteAsync(accountNick, realmType, GetLanguage());
|
||||
|
||||
CheckErrors(accounts.Errors);
|
||||
return accounts.Data?.Players;
|
||||
}
|
||||
|
||||
@@ -27,6 +34,7 @@ namespace WotBlitzStatisticsPro.Blazor.Services
|
||||
var clans =
|
||||
await _client.FindClans.ExecuteAsync(clanNameOrTag, realmType, GetLanguage());
|
||||
|
||||
CheckErrors(clans.Errors);
|
||||
return clans.Data?.Clans;
|
||||
}
|
||||
|
||||
@@ -45,5 +53,39 @@ namespace WotBlitzStatisticsPro.Blazor.Services
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckErrors(IReadOnlyCollection<IClientError> errors)
|
||||
{
|
||||
var messages = new List<string>();
|
||||
|
||||
if (errors.Count > 0)
|
||||
{
|
||||
foreach (var error in errors)
|
||||
{
|
||||
if (error.Extensions != null)
|
||||
{
|
||||
foreach (var errorExt in error.Extensions)
|
||||
{
|
||||
var serializedError = errorExt.Value;
|
||||
if (serializedError is string realError)
|
||||
{
|
||||
var jObject = JObject.Parse(realError);
|
||||
var firstErrorInfo = jObject["errors"]?[0];
|
||||
var message = firstErrorInfo?["extensions"]?["message"];
|
||||
if (message != null)
|
||||
{
|
||||
messages.Add(message.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (messages.Count > 0)
|
||||
{
|
||||
_notificationsService.ReportError("Backend error",string.Join(";", messages));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user