From 7ea70e8f3f9f423db90be200538145071e55c798 Mon Sep 17 00:00:00 2001 From: Joseph Schultz Date: Thu, 30 Dec 2021 09:18:27 -0600 Subject: [PATCH] Fixes #12 - Adds `Errors` list to `SockerResponsePayload` that is either `null` or a `List` of errors. (see: https://github.com/supabase/walrus/#error-states) --- Realtime/Socket.cs | 7 +++++++ RealtimeTests/SocketResponse.cs | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 RealtimeTests/SocketResponse.cs diff --git a/Realtime/Socket.cs b/Realtime/Socket.cs index 7ea4aba..87aaac0 100644 --- a/Realtime/Socket.cs +++ b/Realtime/Socket.cs @@ -403,6 +403,13 @@ public class SocketResponsePayload [JsonProperty("response")] public object Response { get; set; } + + /// + /// Either null or an array of errors. + /// See: https://github.com/supabase/walrus/#error-states + /// + [JsonProperty("errors")] + public List Errors { get; set; } } public class SocketResponsePayload : SocketResponsePayload where T : BaseModel, new() diff --git a/RealtimeTests/SocketResponse.cs b/RealtimeTests/SocketResponse.cs new file mode 100644 index 0000000..1457742 --- /dev/null +++ b/RealtimeTests/SocketResponse.cs @@ -0,0 +1,26 @@ +using System; +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Newtonsoft.Json; +using Supabase.Realtime; + +namespace RealtimeTests +{ + [TestClass] + public class SocketResponseTests + { + [TestMethod("Error Response Included and Deserialized.")] + public void SocketResponseIncludesError() + { + var responseWithError = "{\"columns\":[{\"name\":\"id\",\"type\":\"int8\"},{\"name\":\"details\",\"type\":\"text\"}],\"commit_timestamp\":\"2021-12-28T23:59:38.984538+00:00\",\"schema\":\"public\",\"table\":\"todos\",\"type\":\"UPDATE\",\"old_record\":{\"details\":\"previous test\",\"id\":12,\"user_id\":1},\"record\":{\"details\":\"test...\",\"id\":12,\"user_id\":1},\"errors\":[\"Error 413: Payload Too Large\"]}"; + var errorResponse = JsonConvert.DeserializeObject(responseWithError); + + CollectionAssert.Contains(errorResponse.Errors, "Error 413: Payload Too Large"); + + var responseWithoutError = "{\"columns\":[{\"name\":\"id\",\"type\":\"int8\"},{\"name\":\"details\",\"type\":\"text\"}],\"commit_timestamp\":\"2021-12-28T23:59:38.984538+00:00\",\"schema\":\"public\",\"table\":\"todos\",\"type\":\"UPDATE\",\"old_record\":{\"details\":\"previous test\",\"id\":12,\"user_id\":1},\"record\":{\"details\":\"test...\",\"id\":12,\"user_id\":1},\"errors\": null}"; + var successResponse = JsonConvert.DeserializeObject(responseWithoutError); + + Assert.IsNull(successResponse.Errors); + } + } +}