コード例 #1
0
        private async Task ProcessUnKnownExceptionAsync(IDomainCommand command, Exception exception, CancellationToken token)
        {
            _logger.LogError($"Handling domain command[Id: {command.Id}, Type: {command.GetType().FullName}, application command[{command.ApplicationCommandId}, {command.ApplicationCommandType}, reply scheme: {command.ApplicationCommandReplyScheme}], aggregate root[{command.AggregateRootId},{command.AggregateRootType.FullName}], has a unknown exceptionException: {LogFormatter.PrintException(exception)}.");

            var canReturnOnDomainCommandHandled = command.ApplicationCommandReplyScheme == ApplicationCommandReplySchemes.OnDomainCommandHandled;

            if (!canReturnOnDomainCommandHandled)
            {
                return;
            }

            var domainExceptionMessage = new DomainExceptionMessage()
            {
                Message = exception.Message
            };

            domainExceptionMessage.FillFrom(command);

            await PublishDomainExceptionAsync(domainExceptionMessage, token);
        }
コード例 #2
0
        private async Task ProcessDomainExceptionAsync(IDomainCommand command, DomainException domainException, CancellationToken token)
        {
            var commandId   = command.Id;
            var commandType = command.GetType().FullName;
            var canReturnOnDomainCommandHandled = command.ApplicationCommandReplyScheme == ApplicationCommandReplySchemes.OnDomainCommandHandled;

            _logger.LogError($"Handling domain command has a domain exception, Id: {commandId}, Type: {commandType}, Exception: {LogFormatter.PrintException(domainException)}.");

            if (!canReturnOnDomainCommandHandled)
            {
                return;
            }

            var domainExceptionMessage = new DomainExceptionMessage()
            {
                Message = domainException.Message,
                Code    = domainException.Code
            };

            domainExceptionMessage.FillFrom(command);

            await PublishDomainExceptionAsync(domainExceptionMessage, token);
        }