parent
98e6386d36
commit
39ed6a9ac7
@ -1,6 +1,6 @@
|
||||
namespace AdminPanel.Models;
|
||||
|
||||
public record Team(string Name, string Picture, string MainColor, string SecondColor)
|
||||
public record Team(uint Id, string Name, string Picture, string MainColor, string SecondColor)
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using System.Text;
|
||||
using AdminPanel.Services;
|
||||
using MudBlazor;
|
||||
|
||||
namespace AdminPanel.Pages;
|
||||
|
||||
public class DisplayUtils
|
||||
{
|
||||
public static void ShowErrors(ServiceException e, ISnackbar snackbar)
|
||||
{
|
||||
foreach (var erronedArgument in e.ArgumentMessages)
|
||||
{
|
||||
var sb = new StringBuilder(erronedArgument.Key);
|
||||
sb.Append(" :");
|
||||
|
||||
foreach (var message in erronedArgument.Value)
|
||||
{
|
||||
sb.Append("\n\t-");
|
||||
sb.Append(message);
|
||||
}
|
||||
snackbar.Add(sb.ToString());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
|
||||
namespace AdminPanel.Services;
|
||||
|
||||
public class ErrorsUtils
|
||||
{
|
||||
private record ServerErrorMessageDto(string? Field, string? Error, string Message);
|
||||
|
||||
public static async Task EnsureResponseIsOk(HttpResponseMessage response)
|
||||
{
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var content = await response.Content.ReadFromJsonAsync<ServerErrorMessageDto[]>();
|
||||
var messages = content!
|
||||
.GroupBy(e => e.Field ?? e.Error!)
|
||||
.ToDictionary(
|
||||
g => g.Key,
|
||||
g => g.ToList().ConvertAll(e => e.Message)
|
||||
);
|
||||
|
||||
throw new ServiceException("Server refused request", messages);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue