Exemplo n.º 1
0
        public void Promote(string id)
        {
            ErrorStack entity = GetEntity(id);

            if (entity == null)
            {
                throw new HttpResponseException(base.NotFoundErrorResponseMessage(id));
            }

            if (!_billingManager.HasPremiumFeatures(entity.OrganizationId))
            {
                throw new HttpResponseException(PlanLimitReached("Promote to External is a premium feature used to promote an error stack to an external system. Please upgrade your plan to enable this feature."));
            }

            List <ProjectHook> promotedProjectHooks = _projectHookRepository.GetByProjectId(entity.ProjectId).Where(p => p.EventTypes.Contains(ProjectHookRepository.EventTypes.StackPromoted)).ToList();

            if (!promotedProjectHooks.Any())
            {
                throw new HttpResponseException(Request != null
                    ? Request.CreateErrorResponse(HttpStatusCode.NotImplemented, "No promoted web hooks are configured for this project. Please add a promoted web hook to use this feature.")
                    : new HttpResponseMessage(HttpStatusCode.NotImplemented));
            }

            using (IMessageProducer messageProducer = _messageFactory.CreateMessageProducer()) {
                foreach (ProjectHook hook in promotedProjectHooks)
                {
                    messageProducer.Publish(new WebHookNotification {
                        ProjectId = hook.ProjectId,
                        Url       = hook.Url,
                        Data      = WebHookErrorStack.FromErrorStack(entity, _projectRepository, _organizationRepository)
                    });
                }
            }
        }
        public override void Process(ErrorPipelineContext ctx)
        {
            var organization = _organizationRepository.GetByIdCached(ctx.Error.OrganizationId);

            // if they don't have premium features, then we don't need to queue notifications
            if (organization != null && !organization.HasPremiumFeatures)
            {
                return;
            }

            using (IMessageProducer messageProducer = _messageFactory.CreateMessageProducer()) {
                messageProducer.Publish(new ErrorNotification {
                    ErrorId      = ctx.Error.Id,
                    ErrorStackId = ctx.Error.ErrorStackId,
                    FullTypeName = ctx.StackingInfo.FullTypeName,
                    IsNew        = ctx.IsNew,
                    IsCritical   = ctx.Error.Tags != null && ctx.Error.Tags.Contains("Critical"),
                    IsRegression = ctx.IsRegression,
                    Message      = ctx.StackingInfo.Message,
                    ProjectId    = ctx.Error.ProjectId,
                    Code         = ctx.Error.Code,
                    UserAgent    = ctx.Error.RequestInfo != null ? ctx.Error.RequestInfo.UserAgent : null,
                    Url          = ctx.Error.RequestInfo != null ? ctx.Error.RequestInfo.GetFullPath(true, true) : null
                });

                foreach (ProjectHook hook in _projectHookRepository.GetByProjectId(ctx.Error.ProjectId))
                {
                    bool shouldCall = hook.EventTypes.Contains(ProjectHookRepository.EventTypes.NewError) && ctx.IsNew ||
                                      hook.EventTypes.Contains(ProjectHookRepository.EventTypes.ErrorRegression) && ctx.IsRegression ||
                                      hook.EventTypes.Contains(ProjectHookRepository.EventTypes.CriticalError) && ctx.Error.Tags != null && ctx.Error.Tags.Contains("Critical");

                    if (!shouldCall)
                    {
                        continue;
                    }

                    Log.Trace().Project(ctx.Error.ProjectId).Message("Web hook queued: project={0} url={1}", ctx.Error.ProjectId, hook.Url).Write();

                    messageProducer.Publish(new WebHookNotification {
                        ProjectId = ctx.Error.ProjectId,
                        Url       = hook.Url,
                        Data      = WebHookError.FromError(ctx, _projectRepository, _errorStackRepository, _organizationRepository)
                    });
                }
            }
        }