diff options
| author | JP Dillingham <jp@dillingham.me> | 2024-11-08 08:25:26 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-08 08:25:26 -0600 |
| commit | d689ac95d053b0b0d60c0ceb882d10332a40a8cb (patch) | |
| tree | 2815c3d9eea7a9d27ca1e207c2879235232a7f18 /src/slskd/Events | |
| parent | fd179ee6c888f03ffe26288c906a53961808352f (diff) | |
| parent | e7aefd66f1992dcecd9454df0771e1f29fae2b1d (diff) | |
| download | slskd-d689ac95d053b0b0d60c0ceb882d10332a40a8cb.tar.gz | |
Merge branch 'master' into noop
Diffstat (limited to 'src/slskd/Events')
| -rw-r--r-- | src/slskd/Events/API/EventsController.cs | 33 | ||||
| -rw-r--r-- | src/slskd/Events/EventBus.cs | 8 |
2 files changed, 33 insertions, 8 deletions
diff --git a/src/slskd/Events/API/EventsController.cs b/src/slskd/Events/API/EventsController.cs index e9780fad..46afa5c7 100644 --- a/src/slskd/Events/API/EventsController.cs +++ b/src/slskd/Events/API/EventsController.cs @@ -17,6 +17,8 @@ namespace slskd.Events.API; +using System; +using System.Collections.Generic; using Asp.Versioning; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -42,13 +44,24 @@ public class EventsController : ControllerBase private EventService Events { get; } private ILogger Log { get; } = Serilog.Log.ForContext<EventsController>(); - [HttpGet("")] + /// <summary> + /// Retrieves a paginated list of past <see cref="Event"/> records. + /// </summary> + /// <param name="offset">The offset (number of records) at which to start the requested page.</param> + /// <param name="limit">The page size.</param> + /// <returns>The list of <see cref="Event"/> records.</returns> + [HttpGet("", Name = nameof(GetEvents))] [Authorize(Policy = AuthPolicy.Any)] + [ProducesResponseType(typeof(string), 400)] + [ProducesResponseType(401)] + [ProducesResponseType(403)] + [ProducesResponseType(typeof(IEnumerable<EventRecord>), 200)] + [ProducesResponseType(typeof(string), 500)] public IActionResult GetEvents([FromQuery] int offset = 0, [FromQuery] int limit = 100) { if (offset < 0) { - return BadRequest("Offset must be greater than or equal to zero."); + return BadRequest("Offset must be greater than or equal to zero"); } if (limit <= 0) @@ -56,11 +69,19 @@ public class EventsController : ControllerBase return BadRequest("Limit must be greater than zero"); } - var events = Events.Get(offset, limit); - var count = Events.Count(); + try + { + var eventRecords = Events.Get(offset, limit); + var count = Events.Count(); - Response.Headers.Append("X-Total-Count", count.ToString()); + Response.Headers.Append("X-Total-Count", count.ToString()); - return Ok(events); + return Ok(eventRecords); + } + catch (Exception ex) + { + Log.Error(ex, "Failed to list events: {Message}", ex.Message); + throw; + } } }
\ No newline at end of file diff --git a/src/slskd/Events/EventBus.cs b/src/slskd/Events/EventBus.cs index 16b7c9e1..ae3350f0 100644 --- a/src/slskd/Events/EventBus.cs +++ b/src/slskd/Events/EventBus.cs @@ -88,7 +88,9 @@ public class EventBus // we don't care about any of these tasks; contractually we are only obligated to invoke them _ = Task.WhenAll(subscribers.Select(subscriber => Task.Run(() => (subscriber.Value as Func<T, Task>)(data)) - .ContinueWith(task => Log.Error(task.Exception, "Subscriber {Name} for {Type} encountered an error: {Message}", subscriber.Key, typeof(T), task.Exception.Message)))); + .ContinueWith( + task => Log.Error(task.Exception, "Subscriber {Name} for {Type} encountered an error: {Message}", subscriber.Key, typeof(T), task.Exception.Message), + continuationOptions: TaskContinuationOptions.OnlyOnFaulted))); } else { @@ -103,7 +105,9 @@ public class EventBus // we don't care about any of these tasks; contractually we are only obligated to invoke them _ = Task.WhenAll(subscribers.Select(subscriber => Task.Run(() => (subscriber.Value as Func<Event, Task>)(data)) - .ContinueWith(task => Log.Error(task.Exception, "Catch-All Subscriber {Name} for {Type} encountered an error: {Message}", subscriber.Key, typeof(Event), task.Exception.Message)))); + .ContinueWith( + task => Log.Error(task.Exception, "Catch-All Subscriber {Name} for {Type} encountered an error: {Message}", subscriber.Key, typeof(Event), task.Exception.Message), + continuationOptions: TaskContinuationOptions.OnlyOnFaulted))); } } |
