Add register with validation
1 files changed, 87 insertions, 0 deletions
diff --git a/testFrontend/SafeNSound.Sdk/SafeNSoundException.cs b/testFrontend/SafeNSound.Sdk/SafeNSoundException.cs
new file mode 100644
index 0000000..8915d19
--- /dev/null
+++ b/testFrontend/SafeNSound.Sdk/SafeNSoundException.cs
@@ -0,0 +1,87 @@
+using System.Diagnostics.CodeAnalysis;
+using System.Text.Json.Nodes;
+using System.Text.Json.Serialization;
+using ArcaneLibs.Extensions;
+
+// ReSharper disable MemberCanBePrivate.Global
+
+namespace SafeNSound.Sdk;
+
+public class SafeNSoundExceptionContent {
+ [JsonPropertyName("errCode")]
+ public required string ErrorCode { get; set; }
+
+ [JsonPropertyName("message")]
+ public required string Error { get; set; }
+
+ [JsonPropertyName("soft_logout")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ public bool? SoftLogout { get; set; }
+
+ [JsonPropertyName("retry_after_ms")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ public int? RetryAfterMs { get; set; }
+
+ [JsonExtensionData]
+ public Dictionary<string, object> AdditionalData { get; set; } = new();
+}
+
+public class SafeNSoundException : Exception {
+ [JsonPropertyName("errCode")]
+ public required string ErrorCode { get; set; }
+
+ [JsonPropertyName("message")]
+ public required string Error { get; set; }
+
+ [JsonPropertyName("soft_logout")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ public bool? SoftLogout { get; set; }
+
+ [JsonPropertyName("retry_after_ms")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ public int? RetryAfterMs { get; set; }
+
+ public string RawContent { get; set; }
+
+ [JsonExtensionData]
+ public Dictionary<string, object> AdditionalData { get; set; } = new();
+
+ public object GetAsObject() => new SafeNSoundExceptionContent()
+ { ErrorCode = ErrorCode, Error = Error, SoftLogout = SoftLogout, RetryAfterMs = RetryAfterMs, AdditionalData = AdditionalData };
+
+ public string GetAsJson() => GetAsObject().ToJson(ignoreNull: true);
+
+ public override string Message =>
+ $"{ErrorCode}: " +
+ (!string.IsNullOrWhiteSpace(Error)
+ ? Error
+ : ErrorCode switch {
+ _ => $"Unknown error: {GetAsJson()}"
+ });
+
+ [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Follows spec naming")]
+ public static class ErrorCodes {
+ public const string INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR";
+ }
+}
+
+public class SafeNSoundClientException : 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}";
+
+ [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Follows spec naming")]
+ public static class ErrorCodes {
+ }
+}
\ No newline at end of file
|