private async Task handleCustomExceptions(BaseException ex, HttpContext httpContext)
        {
            if (ex.code == 0)
            {
                ex.code = HttpStatusCode.InternalServerError;
            }

            var response = new QueueExceptionDto();

            response.Message      = ex.Message;
            response.Status       = ex.code.ToString();
            response.RequestedUri = httpContext.Request.Path;
            response.Timestamp    = DateTime.Now.ToString("yyyy-MM-dd HH:mm tt");
            response.Origin       = ex.origin;

            httpContext.Response.ContentType = "application/json";
            httpContext.Response.StatusCode  = (int)ex.code;

            await httpContext.Response.WriteAsync(response.SerializeModel());

            if (ex.code.Equals(HttpStatusCode.InternalServerError))
            {
                _manager.Publish(response);
            }
        }
Ejemplo n.º 2
0
        public async Task Received <TCommand, TResult>(object model, BasicDeliverEventArgs ea) where TCommand : class where TResult : class
        {
            TResult result = default;

            var body       = ea.Body.ToArray();
            var props      = ea.BasicProperties;
            var replyProps = RabbitMq.CreateBasicProperties();

            replyProps.CorrelationId = props.CorrelationId;
            replyProps.Persistent    = true;

            try
            {
                var message = Encoding.UTF8.GetString(body);
                var command = JsonConvert.DeserializeObject <TCommand>(message);
                result = (TResult)await Mediator.Send(command !);
            }
            catch (Exception e)
            {
                Logger.LogError(e, e.Message);
            }
            finally
            {
                RabbitMq.Publish(result, replyProps);
                RabbitMq.Ack(deliveryTag: ea.DeliveryTag, multiple: false);
            }
        }