public void Consume(ReceiveErrorMessage message)
 {
     _receiveErrorCommand.Invoke(new ReceiveErrorRequest
     {
         Error           = message.Error,
         ApplicationId   = message.ApplicationId,
         Organisation    = message.Organisation,
         Token           = message.Token,
         ExistingIssueId = message.ExistingIssueId
     });
 }
Beispiel #2
0
        public HttpResponseMessage Post(string orgId, ReceiveErrorRequest request)
        {
            try
            {
                SetOrganisation(orgId);
                Auditor.Trace(GetType(), "Started...");
                var response = _receiveErrorCommand.Invoke(request);
                Session.Commit();

                return(Request.CreateResponse(HttpStatusCode.OK, response));
            }
            catch (Exception e)
            {
                Auditor.Error(GetType(), e);
                throw;
            }
        }
        public ProcessIncomingExceptionResponse Invoke(ProcessIncomingExceptionRequest request)
        {
            TraceObject(request.Error);

            Application  application;
            Organisation organisation;
            var          status         = TryGetApplication(request.Error.Token, out application, out organisation);
            string       applicationId  = null;
            string       organisationId = null;

            switch (status)
            {
            case ApplicationStatus.Inactive:
                return(new ProcessIncomingExceptionResponse
                {
                    ResponseMessage = "The application specified in the token is not currently active",
                    ResponseCode = HttpStatusCode.NotAcceptable,
                });

            case ApplicationStatus.NotFound:
                return(new ProcessIncomingExceptionResponse
                {
                    ResponseMessage = "The application specified in the token could not be found",
                    ResponseCode = HttpStatusCode.Unauthorized,
                });

            case ApplicationStatus.Error:
                return(new ProcessIncomingExceptionResponse
                {
                    ResponseCode = HttpStatusCode.InternalServerError,
                    ResponseMessage = "An unhandled error occured while attempting to store this error"
                });

            case ApplicationStatus.InvalidOrganisation:
                return(new ProcessIncomingExceptionResponse
                {
                    ResponseMessage = "Failed to locate the organisation specified in your token",
                    ResponseCode = HttpStatusCode.Unauthorized,
                });

            case ApplicationStatus.InvalidToken:
                return(new ProcessIncomingExceptionResponse
                {
                    ResponseMessage = "The token supplied is invalid, please check your token in the applications page in Errordite",
                    ResponseCode = HttpStatusCode.BadRequest,
                });

            case ApplicationStatus.Ok:
            {
                applicationId  = application.Id;
                organisationId = application.OrganisationId;
            }
            break;
            }

            RateLimiterRule failedRule;

            if ((failedRule = _exceptionRateLimiter.Accept(applicationId)) != null)
            {
                Trace("Failed rate limiter rule named {0}", failedRule.Name);
                return(new ProcessIncomingExceptionResponse
                {
                    ResponseMessage = "The error was not stored due to limits on the number of errors we can receive for you in a given time frame",
                    SpecialResponseCode = 429, //too many requests http://tools.ietf.org/html/draft-nottingham-http-new-status-02
                });
            }

            var error = request.Error.GetError(application);

            if (_configuration.ServiceBusEnabled)
            {
                _sender.Send(new ReceiveErrorMessage
                {
                    Error          = error,
                    ApplicationId  = applicationId,
                    OrganisationId = organisationId,
                    Token          = request.Error.Token,
                },
                             _configuration.GetReceiveQueueAddress(organisation.FriendlyId));
                Session.AddCommitAction(new PollNowCommitAction(organisation));
            }
            else
            {
                Trace("ServiceBus is disabled, invoking IReceiveErrorCommand");

                _receiveErrorCommand.Invoke(new ReceiveErrorRequest
                {
                    Error         = error,
                    ApplicationId = applicationId,
                    Organisation  = organisation,
                    Token         = request.Error.Token
                });
            }

            return(new ProcessIncomingExceptionResponse());
        }