~ruther/NosSmooth.Comms

732cdbfc1478a3a9c4722c8b7c59b1c325d3258a — František Boháček 2 years ago 6c7a610
feat: safely call message responders to catch exceptions
1 files changed, 13 insertions(+), 1 deletions(-)

M src/Core/NosSmooth.Comms.Core/MessageHandler.cs
M src/Core/NosSmooth.Comms.Core/MessageHandler.cs => src/Core/NosSmooth.Comms.Core/MessageHandler.cs +13 -1
@@ 91,7 91,7 @@ public class MessageHandler

        var responders = scope.ServiceProvider
            .GetServices<IMessageResponder<TMessage>>()
            .Select(x => x.Respond(data, ct))
            .Select(x => SafeCall(x.Respond(data, ct)))
            .ToArray();

        var results = (await Task.WhenAll(responders))


@@ 130,4 130,16 @@ public class MessageHandler

        return result;
    }

    private async Task<Result> SafeCall(Task<Result> respond)
    {
        try
        {
            return await respond;
        }
        catch (Exception e)
        {
            return e;
        }
    }
}
\ No newline at end of file

Do not follow this link