about summary refs log tree commit diff
path: root/LibMatrix/LibMatrixException.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-04-25 06:31:11 +0200
committerRory& <root@rory.gay>2024-04-25 06:31:11 +0200
commit5ca0a45606ad2ca7e1ca45a3b27be08e9640dd9d (patch)
tree6a04296d6fd93cb090b5d91ae9ca44ef45c7e34e /LibMatrix/LibMatrixException.cs
parentPartial User-Interactive Authentication, allow skipping homeserver typing (diff)
downloadLibMatrix-5ca0a45606ad2ca7e1ca45a3b27be08e9640dd9d.tar.xz
Fixes
Diffstat (limited to 'LibMatrix/LibMatrixException.cs')
-rw-r--r--LibMatrix/LibMatrixException.cs27
1 files changed, 27 insertions, 0 deletions
diff --git a/LibMatrix/LibMatrixException.cs b/LibMatrix/LibMatrixException.cs
new file mode 100644
index 0000000..5854826
--- /dev/null
+++ b/LibMatrix/LibMatrixException.cs
@@ -0,0 +1,27 @@
+using System.Text.Json.Serialization;
+using ArcaneLibs.Extensions;
+
+namespace LibMatrix;
+
+public class LibMatrixException : Exception {
+    [JsonPropertyName("errcode")]
+    public required string ErrorCode { get; set; }
+
+    [JsonPropertyName("error")]
+    public required string Error { get; set; }
+
+
+    public object GetAsObject() => new { errcode = ErrorCode, error = Error };
+    public string GetAsJson() => GetAsObject().ToJson(ignoreNull: true);
+
+    public override string Message =>
+        $"{ErrorCode}: {ErrorCode switch {
+            "M_UNSUPPORTED" => "The requested feature is not supported",
+            _ => $"Unknown error: {GetAsObject().ToJson(ignoreNull: true)}"
+        }}\nError: {Error}";
+
+    public static class ErrorCodes {
+        public const string M_NOT_FOUND = "M_NOT_FOUND";
+        public const string M_UNSUPPORTED = "M_UNSUPPORTED";
+    }
+}
\ No newline at end of file