From 2fa19a76b8f4ef72690f2d8ea0dd77ef2c5397da Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Fri, 13 Oct 2023 13:09:27 +0200 Subject: Error handling --- LibMatrix/RoomTypes/GenericRoom.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'LibMatrix/RoomTypes') diff --git a/LibMatrix/RoomTypes/GenericRoom.cs b/LibMatrix/RoomTypes/GenericRoom.cs index 1c0633c..106b2f6 100644 --- a/LibMatrix/RoomTypes/GenericRoom.cs +++ b/LibMatrix/RoomTypes/GenericRoom.cs @@ -66,6 +66,16 @@ public class GenericRoom { } } + public async Task GetStateOrNullAsync(string type, string stateKey = "") { + try { + return await GetStateAsync(type, stateKey); + } + catch (MatrixException e) { + if (e.ErrorCode == "M_NOT_FOUND") return default; + throw; + } + } + public async Task GetMessagesAsync(string from = "", int limit = 10, string dir = "b", string filter = "") { var url = $"/_matrix/client/v3/rooms/{RoomId}/messages?from={from}&limit={limit}&dir={dir}"; -- cgit 1.4.1