Skip to content

Commit

Permalink
Do not throw error when event is not registered
Browse files Browse the repository at this point in the history
  • Loading branch information
Somfic committed Oct 13, 2023
1 parent 2ef07e3 commit 138e8e5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion EliteAPI.Abstractions/Events/IEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public interface IEvents
/// <summary>Converts the JSON to a registered event type and invokes the registered event handlers.</summary>
/// <param name="json">The event JSON</param>
/// <param name="context">The context of the event</param>
IEvent Invoke(string json, EventContext context);
IEvent? Invoke(string json, EventContext context);

/// <summary>Discovers and registers all the events in the specified assembly.</summary>
/// <param name="assembly">The assembly the events are defined in</param>
Expand Down
2 changes: 1 addition & 1 deletion EliteAPI.Tests/JournalManual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void Json(string json)

var invokedEvent = _events.Invoke(json, new EventContext());

Assert.That(invokedEvent, Is.Not.Null, $"Event is null");
Assert.That(invokedEvent, Is.Not.Null, $"Event is not registered: {json}");

// Check if the event is the correct type
var eventType = invokedEvent.GetType();
Expand Down
4 changes: 2 additions & 2 deletions EliteAPI/Events/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public IEvent Invoke<TEvent>(TEvent @event, EventContext context) where TEvent :
}

/// <inheritdoc />
public IEvent Invoke(string json, EventContext context)
public IEvent? Invoke(string json, EventContext context)
{
try
{
Expand Down Expand Up @@ -241,7 +241,7 @@ public IEvent Invoke(string json, EventContext context)
InvokeAnyHandlers(eventType, json, context);

if (eventType == null)
throw new Exception($"The {eventName} event is not registered"); // todo: better exception type
return null;

var parsedEvent = _eventParser.FromJson(eventType, json);

Expand Down

0 comments on commit 138e8e5

Please sign in to comment.