Exemplo n.º 1
0
        public static bool IsTransientNetworkError(Exception e, out string code)
        {
            const string Tag = "IsTransientNetworkError";

            code = String.Empty;
            foreach (var exception in Misc.Flatten(e))
            {
                if (exception is IOException ||
                    exception is TimeoutException ||
                    exception is SocketException)
                {
                    code = e.GetType().Name;
                    Log.To.Sync.V(Tag, "Rule #1: Exception is IOException, TimeoutException, or SocketException, " +
                                  "ruling transient...", exception);
                    return(true);
                }

                var we = exception as WebException;
                if (we == null)
                {
                    Log.To.Sync.V(Tag, "No further information can be gained from this exception, " +
                                  "attempting to find other nested exceptions...", exception);
                    if (!String.IsNullOrEmpty(code))
                    {
                        code = e.GetType().Name;
                    }
                    continue;
                }

                if (we.Status == WebExceptionStatus.ConnectFailure || we.Status == WebExceptionStatus.Timeout ||
                    we.Status == WebExceptionStatus.ConnectionClosed || we.Status == WebExceptionStatus.RequestCanceled)
                {
                    Log.To.Sync.V(Tag, "Rule #2: Exception is WebException and status is ConnectFailure, Timeout, " +
                                  "ConnectionClosed, or RequestCanceled, ruling transient...", we);
                    code = we.Status.ToString();
                    return(true);
                }

                var statusCode = GetStatusCode(we);
                if (!statusCode.HasValue)
                {
                    Log.To.Sync.V(Tag, "No further information can be gained from this WebException (missing response?), " +
                                  "attempting to find other nested exceptions...", we);
                    code = we.Status.ToString();
                    continue;
                }

                if (IsTransientError(((HttpWebResponse)we.Response).StatusCode))
                {
                    Log.To.Sync.V(Tag, "Rule #3: {0} is considered a transient error code, ruling transient...",
                                  ((HttpWebResponse)we.Response).StatusCode);
                    code = statusCode.Value.ToString();
                    return(true);
                }
            }

            Log.To.Sync.V(Tag, "No transient exceptions found, ruling fatal...");
            return(false);
        }
Exemplo n.º 2
0
        internal Status UpdateIndex_Internal()
        {
            var status = new Status(StatusCode.Unknown);

            try {
                status.Code = Storage.UpdateIndexes(ViewsInGroup().Select(x => x.Storage)) ? StatusCode.Ok :
                              StatusCode.DbError;
            } catch (Exception e) {
                var innerException = Misc.Flatten(e).First() as CouchbaseLiteException;
                if (innerException != null)
                {
                    status.Code = innerException.Code;
                }
                else
                {
                    status.Code = StatusCode.Exception;
                }
            }

            return(status);
        }