Esempio n. 1
0
        protected override async Task <HttpResponseMessage> SendAsync(
            HttpRequestMessage request, CancellationToken cancellationToken)
        {
            try
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                var result = await _behaviorChainInvoker.Invoke(
                    _actionDescriptor, request, cancellationToken);

                stopwatch.Stop();

                if (_configuration.EnableMetrics)
                {
                    _metrics.IncrementRequests();
                    _actionMetrics.AddRequestTime(stopwatch.Elapsed);
                }

                return(result);
            }
            catch (Exception exception)
            {
                if (exception is GraphiteRuntimeInitializationException)
                {
                    throw;
                }
                throw new UnhandledGraphiteRequestException(exception);
            }
        }
        protected override async Task <HttpResponseMessage> SendAsync(
            HttpRequestMessage requestMessage, CancellationToken cancellationToken)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            try
            {
                return(await _behaviorChainInvoker.Invoke(
                           _actionDescriptor, requestMessage, cancellationToken));
            }
            catch (BadRequestException exception)
            {
                var response = requestMessage.CreateResponse(HttpStatusCode.BadRequest);
                response.SafeSetReasonPhrase(exception.Message);
                return(response);
            }
            catch (Exception exception)
            {
                if (exception is UnhandledGraphiteException)
                {
                    throw;
                }
                throw new UnhandledGraphiteException(_actionDescriptor,
                                                     _container, exception);
            }
            finally
            {
                stopwatch.Stop();
                if (_configuration.Metrics)
                {
                    _metrics.IncrementRequests();
                    _actionMetrics.AddRequestTime(stopwatch.Elapsed);
                }
            }
        }