示例#1
0
        public static B2Exception GetExceptionForError(B2ErrorResponseOutputDTO error)
        {
            switch (error.Status)
            {
            case 400:
                if (error.Message == "Sha1 did not match data received")
                {
                    return(new B2HashMismatchException(error));
                }
                else
                {
                    return(new B2Exception(error));
                }

            case 401:
                throw new B2BadAuthTokenException(error);

            case 503:
                if (error.Code == "service_unavailable")
                {
                    return(new B2ServerBusyException(error));
                }
                else
                {
                    return(new B2Exception(error));
                }

            default:
                return(new B2Exception(error));
            }
        }
示例#2
0
        /// <summary>
        /// Can an upload potentially be recovered by retrying after supplied error
        /// </summary>
        public static bool IsRecoverableError(B2ErrorResponseOutputDTO error)
        {
            var exception = GetExceptionForError(error);

            if (exception is B2HashMismatchException)
            {
                return(true);
            }
            else if (exception is B2BadAuthTokenException)
            {
                return(true);
            }
            else if (exception is B2ServerBusyException)
            {
                return(true);
            }

            return(false);
        }
示例#3
0
 public static void ThrowException(B2ErrorResponseOutputDTO error)
 {
     throw GetExceptionForError(error);
 }
示例#4
0
        public static void ThrowException(string errorJson)
        {
            B2ErrorResponseOutputDTO error = JsonSerializer.Deserialize <B2ErrorResponseOutputDTO>(errorJson);

            throw GetExceptionForError(error);
        }
 public B2HashMismatchException(B2ErrorResponseOutputDTO error) : base(error)
 {
 }
示例#6
0
 public B2ServerBusyException(B2ErrorResponseOutputDTO error) : base(error)
 {
 }
示例#7
0
 public B2Exception(B2ErrorResponseOutputDTO error) : base(error.ToString())
 {
 }
示例#8
0
 public B2BadAuthTokenException(B2ErrorResponseOutputDTO error) : base(error)
 {
 }