Skip to content

Commit

Permalink
feat: Add Exception type for Event errors (#217)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas Pedroza <[email protected]>
  • Loading branch information
cynicaljoy and pnwpedro authored Nov 7, 2024
1 parent 6edb88f commit 74e08fb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Fauna.Test/Integration.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ await _client.EventFeedAsync<StreamingSandbox>(FQL($"42"))
[Test, Category("EventFeed")]
public void ThrowsWhenStartTsIsTooOld()
{
var ex = Assert.ThrowsAsync<FaunaException>(async () =>
var ex = Assert.ThrowsAsync<EventException>(async () =>
{
long aYearAgo = DateTimeOffset.UtcNow.AddYears(-1).ToUnixTimeMilliseconds() * 1000;
var feed = await _client.EventFeedAsync<StreamingSandbox>(
Expand Down
15 changes: 15 additions & 0 deletions Fauna/Exceptions/EventException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Fauna.Core;

namespace Fauna.Exceptions;

/// <summary>
/// Represents an exception related to Fauna Event Stream and Event Feed errors.
/// </summary>
public class EventException : ServiceException
{
/// <summary>
/// Initializes a new instance of the <see cref="EventException"/> class.
/// </summary>
/// <param name="err">The <see cref="ErrorInfo"/> from which to extract a message.</param>
public EventException(ErrorInfo err) : base(message: err.Message!) { }
}
4 changes: 2 additions & 2 deletions Fauna/Types/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ public class Event<T> where T : notnull
/// <param name="json">JSON Element to convert.</param>
/// <param name="ctx">A mapping context to influence deserialization.</param>
/// <returns>An instance of <see cref="Event{T}"/>.</returns>
/// <exception cref="FaunaException">Thrown when the event includes a Fauna error.</exception>
/// <exception cref="EventException">Thrown when the event includes a Fauna error.</exception>
internal static Event<T> From(JsonElement json, MappingContext ctx)
{
var err = GetError(json);
if (err != null)
{
throw new FaunaException(err.Value);
throw new EventException(err.Value);
}

var evt = new Event<T>
Expand Down

0 comments on commit 74e08fb

Please sign in to comment.