Example #1
0
        internal static IErrorResolution Solve(HttpStatusCode statusCode, ExceptionResolverOptions options)
        {
            if (!IsTransientError(statusCode))
            {
                return(new ErrorResolution_Impl(statusCode.ToString(), ErrorResolutionFlags.Permanent)
                {
                    Resolution = ErrorResolution.Stop
                });
            }

            if (options.HasRetries)
            {
                return(new ErrorResolution_Impl(statusCode.ToString(), ErrorResolutionFlags.Transient)
                {
                    Resolution = ErrorResolution.BackoffAndRetry
                });
            }

            if (options.Continuous)
            {
                return(new ErrorResolution_Impl(statusCode.ToString(), ErrorResolutionFlags.Transient | ErrorResolutionFlags.OutOfRetries)
                {
                    Resolution = ErrorResolution.RetryLater
                });
            }
            else
            {
                return(new ErrorResolution_Impl(statusCode.ToString(), ErrorResolutionFlags.Transient | ErrorResolutionFlags.OutOfRetries)
                {
                    Resolution = ErrorResolution.Stop
                });
            }
        }
Example #2
0
        internal static IErrorResolution Solve(Exception e, ExceptionResolverOptions options)
        {
            if (e == null)
            {
                // No error occurred, keep going if continuous
                return(options.Continuous ?
                       new ErrorResolution_Impl(null, ErrorResolutionFlags.None)
                {
                    Resolution = ErrorResolution.RetryNow
                }
                    : new ErrorResolution_Impl(null, ErrorResolutionFlags.None)
                {
                    Resolution = ErrorResolution.Stop
                });
            }

            var resolution = Analyze(e);

            if (resolution.ResolutionFlags.HasFlag(ErrorResolutionFlags.Transient))
            {
                if (!options.HasRetries)
                {
                    resolution.ResolutionFlags |= ErrorResolutionFlags.OutOfRetries;
                    resolution.Resolution       = options.Continuous ? ErrorResolution.RetryLater : ErrorResolution.Stop;
                }
                else
                {
                    resolution.Resolution = ErrorResolution.BackoffAndRetry;
                }
            }
            else if (resolution.ResolutionFlags.HasFlag(ErrorResolutionFlags.Connectivity))
            {
                resolution.Resolution = ErrorResolution.GoOffline;
            }
            else
            {
                resolution.Resolution = ErrorResolution.Stop;
            }

            return(resolution);
        }