コード例 #1
0
        /// <summary>
        /// Handles the exception.
        /// </summary>
        /// <param name="exception">The exception.</param>
        /// <param name="response">The response.</param>
        /// <param name="uri">The URI.</param>
        /// <param name="method">The method.</param>
        /// <param name="data">The data.</param>
        /// <param name="result">The result.</param>
        /// <exception cref="UnexpectedApiResponseException"></exception>
        private Exception HandleException(
            Exception exception,
            HttpResponseMessage response,
            Uri uri,
            HttpRequestMethod method,
            string data,
            string result)
        {
            var statusCode = 0;

            if (response != null)
            {
                statusCode = (int)response.StatusCode;
            }

            var ex = new UnexpectedApiResponseException(uri, method.ToString(), data, result, statusCode, exception);

            if (statusCode == 429 ||
                statusCode == 503)
            {
                _requestMediator.Reset();
                LogConsumer.Warning("HTTP {2} status code on method {0} - uri {1}", method.ToString(), uri, statusCode);
                Thread.Sleep(60 * 1000);
                _requestMediator.Set();
                return(ex);
            }
            if (statusCode != 0 &&
                statusCode != 408 &&
                statusCode != 500 &&
                statusCode != 502)
            {
                throw ex;
            }

            LogConsumer.Warning("Retrying the {0} request", method.ToString());
            TelemetryAnalytics.TrackHit($"VTEX_handle_exception_retrying_{method.ToString()}_request");
            return(ex);
        }