From b77cc7edf960c7f49ed5181b9570b4e0afe73583 Mon Sep 17 00:00:00 2001 From: Rory& Date: Fri, 14 Nov 2025 08:42:49 +0100 Subject: Handle some non-browser network errors, clean up some well known resolver stuff --- LibMatrix/LibMatrixNetworkException.cs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 LibMatrix/LibMatrixNetworkException.cs (limited to 'LibMatrix/LibMatrixNetworkException.cs') diff --git a/LibMatrix/LibMatrixNetworkException.cs b/LibMatrix/LibMatrixNetworkException.cs new file mode 100644 index 0000000..7be0f4e --- /dev/null +++ b/LibMatrix/LibMatrixNetworkException.cs @@ -0,0 +1,33 @@ +using System.Diagnostics.CodeAnalysis; +using System.Text.Json.Serialization; +using ArcaneLibs.Extensions; +// ReSharper disable MemberCanBePrivate.Global + +namespace LibMatrix; + +public class LibMatrixNetworkException : Exception { + public LibMatrixNetworkException() : base() { } + public LibMatrixNetworkException(Exception httpRequestException) : base("A network error occurred", httpRequestException) { } + + [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 { + ErrorCodes.RLM_NET_UNKNOWN_HOST => "The specified host could not be found.", + ErrorCodes.RLM_NET_INVALID_REMOTE_CERTIFICATE => "The remote server's TLS certificate is invalid or could not be verified.", + _ => $"Unknown error: {GetAsObject().ToJson(ignoreNull: true)}" + }}\nError: {Error}"; + + [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Follows spec naming")] + public static class ErrorCodes { + public const string RLM_NET_UNKNOWN_HOST = "RLM_NET_UNKNOWN_HOST"; + public const string RLM_NET_INVALID_REMOTE_CERTIFICATE = "RLM_NET_INVALID_REMOTE_CERTIFICATE"; + } +} \ No newline at end of file -- cgit 1.5.1