diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-10-13 13:09:27 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-10-13 13:09:27 +0200 |
commit | 2fa19a76b8f4ef72690f2d8ea0dd77ef2c5397da (patch) | |
tree | 8ac9d95c4077a552fcf7ad19231a56fe6edba93d /LibMatrix/RoomTypes | |
parent | Fix alias thing? (diff) | |
download | LibMatrix-bak-2fa19a76b8f4ef72690f2d8ea0dd77ef2c5397da.tar.xz |
Error handling
Diffstat (limited to 'LibMatrix/RoomTypes')
-rw-r--r-- | LibMatrix/RoomTypes/GenericRoom.cs | 10 |
1 files changed, 10 insertions, 0 deletions
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<T?> GetStateOrNullAsync<T>(string type, string stateKey = "") { + try { + return await GetStateAsync<T>(type, stateKey); + } + catch (MatrixException e) { + if (e.ErrorCode == "M_NOT_FOUND") return default; + throw; + } + } + public async Task<MessagesResponse> 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}"; |