Skip to content

Commit

Permalink
Fixes #12 - Adds Errors list to SockerResponsePayload that is eit…
Browse files Browse the repository at this point in the history
…her `null` or a `List<string>` of errors. (see: https://github.com/supabase/walrus/#error-states)
  • Loading branch information
acupofjose committed Dec 30, 2021
1 parent 7f1decf commit 7ea70e8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Realtime/Socket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,13 @@ public class SocketResponsePayload

[JsonProperty("response")]
public object Response { get; set; }

/// <summary>
/// Either null or an array of errors.
/// See: https://github.com/supabase/walrus/#error-states
/// </summary>
[JsonProperty("errors")]
public List<string> Errors { get; set; }
}

public class SocketResponsePayload<T> : SocketResponsePayload where T : BaseModel, new()
Expand Down
26 changes: 26 additions & 0 deletions RealtimeTests/SocketResponse.cs
Original file line number Diff line number Diff line change
@@ -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<SocketResponsePayload>(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<SocketResponsePayload>(responseWithoutError);

Assert.IsNull(successResponse.Errors);
}
}
}

0 comments on commit 7ea70e8

Please sign in to comment.