Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Exception type for Event errors #217

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading