From 5ca0a45606ad2ca7e1ca45a3b27be08e9640dd9d Mon Sep 17 00:00:00 2001 From: Rory& Date: Thu, 25 Apr 2024 06:31:11 +0200 Subject: Fixes --- LibMatrix/LibMatrixException.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 LibMatrix/LibMatrixException.cs (limited to 'LibMatrix/LibMatrixException.cs') 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 -- cgit 1.4.1