Improved error handling when converting and sending server configurations to daemon

This commit is contained in:
Marcel Baumgartner
2024-06-03 20:04:01 +02:00
parent fc863cc422
commit 4401a91d35

View File

@@ -14,12 +14,12 @@ namespace Moonlight.Features.Servers.Http.Controllers;
[ApiController] [ApiController]
[Route("api/servers")] [Route("api/servers")]
[EnableNodeMiddleware] [EnableNodeMiddleware]
public class ServersControllers : Controller public class ServersController : Controller
{ {
private readonly Repository<Server> ServerRepository; private readonly Repository<Server> ServerRepository;
private readonly Repository<ServerBackup> BackupRepository; private readonly Repository<ServerBackup> BackupRepository;
public ServersControllers(Repository<Server> serverRepository, Repository<ServerBackup> backupRepository) public ServersController(Repository<Server> serverRepository, Repository<ServerBackup> backupRepository)
{ {
ServerRepository = serverRepository; ServerRepository = serverRepository;
BackupRepository = backupRepository; BackupRepository = backupRepository;
@@ -56,10 +56,20 @@ public class ServersControllers : Controller
.Where(x => x.Node.Id == node.Id) .Where(x => x.Node.Id == node.Id)
.ToArray(); .ToArray();
// Convert the data to server configurations var serverConfigurations = new List<ServerConfiguration>();
var serverConfigurations = servers
.Select(x => x.ToServerConfiguration()) foreach (var server in servers)
.ToArray(); {
try
{
serverConfigurations.Add(server.ToServerConfiguration());
}
catch (Exception e)
{
Logger.Error($"An error occured while sending server {server.Id} (Image: {server.Image.Name}) to daemon. This may indicate a corrupt or broken image/server. Skipping this server");
Logger.Error(e);
}
}
// Send the amount of configs the node will receive // Send the amount of configs the node will receive
await websocketStream.SendPacket(servers.Length); await websocketStream.SendPacket(servers.Length);