about summary refs log tree commit diff
path: root/BugMine.Sdk
diff options
context:
space:
mode:
Diffstat (limited to 'BugMine.Sdk')
-rw-r--r--BugMine.Sdk/BugMineClient.cs16
-rw-r--r--BugMine.Sdk/Exceptions/BugMineException.cs1
2 files changed, 14 insertions, 3 deletions
diff --git a/BugMine.Sdk/BugMineClient.cs b/BugMine.Sdk/BugMineClient.cs

index 21be614..d55ff4d 100644 --- a/BugMine.Sdk/BugMineClient.cs +++ b/BugMine.Sdk/BugMineClient.cs
@@ -1,3 +1,4 @@ +using System.Text.Json.Serialization; using System.Text.RegularExpressions; using ArcaneLibs.Extensions; using BugMine.Web.Classes.Exceptions; @@ -11,14 +12,14 @@ namespace BugMine.Web.Classes; public class BugMineClient(AuthenticatedHomeserverGeneric homeserver) { public AuthenticatedHomeserverGeneric Homeserver { get; } = homeserver; - public async IAsyncEnumerable<BugMineProject> GetProjects(SemaphoreSlim? semaphore = null) { + public async IAsyncEnumerable<BugMineProject> GetProjects(SemaphoreSlim? semaphore = null, bool ignoreInvalidBoards = false) { List<Task<BugMineProject>> tasks = []; int count = 0; await foreach (var room in homeserver.GetJoinedRoomsByType(BugMineProject.RoomType, 64)) { tasks.Add(room.AsBugMineProject(semaphore)); } - var results = tasks.ToAsyncEnumerable(); + var results = tasks.ToAsyncEnumerable(skipExceptions: ignoreInvalidBoards); await foreach (var result in results) { yield return result; } @@ -75,7 +76,16 @@ public class BugMineClient(AuthenticatedHomeserverGeneric homeserver) { } else { var alias = $"#{projectSlug}"; - var resolveResult = await Homeserver.ResolveRoomAliasAsync(alias); + AliasResult? resolveResult = null; + try { + resolveResult = await Homeserver.ResolveRoomAliasAsync(alias); + } + catch (MatrixException e) { + if (e.ErrorCode == MatrixException.ErrorCodes.M_NOT_FOUND) + throw new BugMineException(BugMineException.ErrorCodes.ProjectNotFound, $"Project with slug {projectSlug} not found"); + throw; + } + if (string.IsNullOrEmpty(resolveResult?.RoomId)) return null; //TODO: fallback to finding via joined rooms' canonical alias event? room = homeserver.GetRoom(resolveResult.RoomId); diff --git a/BugMine.Sdk/Exceptions/BugMineException.cs b/BugMine.Sdk/Exceptions/BugMineException.cs
index 7e843b3..5c81e48 100644 --- a/BugMine.Sdk/Exceptions/BugMineException.cs +++ b/BugMine.Sdk/Exceptions/BugMineException.cs
@@ -19,5 +19,6 @@ public class BugMineException : MatrixException { public new static class ErrorCodes { public const string UserNotInRoom = "BUGMINE_USER_NOT_IN_ROOM"; + public const string ProjectNotFound = "BUGMINE_PROJECT_NOT_FOUND"; } } \ No newline at end of file