Skip to content

Commit 15bc3b0

Browse files
committed
fix: stop service if room is not found
1 parent f62c5ab commit 15bc3b0

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/WinService/Manager/ApiManager.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,25 @@ public ApiManager(ILogger<ApiManager> logger, IHostApplicationLifetime appLifeti
3939

4040
private async Task<ApiModels.Room> GetRoomAsync()
4141
{
42-
if (await GetRoomAsync(Environment.MachineName) is { } room)
42+
try
4343
{
44-
_logger.LogInformation("Room: {roomName} with Id {roomId}", room.DisplayName, room.RoomId);
45-
if (room.Enabled)
44+
if (await GetRoomAsync(Environment.MachineName) is { } room)
45+
{
46+
_logger.LogInformation("Room: {roomName} with Id {roomId}", room.DisplayName, room.RoomId);
47+
if (room.Enabled)
48+
return room;
49+
50+
_logger.LogInformation("Room: {roomName} is disabled", room.DisplayName);
51+
_appLifetime.StopApplication();
4652
return room;
47-
48-
_logger.LogInformation("Room: {roomName} is disabled", room.DisplayName);
49-
_appLifetime.StopApplication();
50-
return room;
53+
}
5154
}
52-
53-
_logger.LogCritical("No room found");
54-
throw new Exception("No room found");
55+
catch (HttpRequestException)
56+
{
57+
_logger.LogCritical("No room found, stopping service");
58+
_appLifetime.StopApplication(); // maybe send user an information via WinClient as this is unexpected?
59+
}
60+
return new ApiModels.Room();
5561
}
5662

5763
private async Task<ApiModels.Computer?> GetComputerAsync()

0 commit comments

Comments
 (0)