Пример #1
0
        /// <summary>
        /// Creates a user facing error message from a failed B2 request.
        /// </summary>
        /// <param name="res">A <see cref="HttpWebResponse"/> with a non-2xx status code.</param>
        /// <returns>A string describing the error.</returns>
        private static string StringifyB2Error(HttpWebResponse res)
        {
            B2Error err = ParseB2Error(res);

            if (err == null)
            {
                return($"Status {res.StatusCode}, unknown error.");
            }

            string colonSpace = string.IsNullOrWhiteSpace(err.message) ? "" : ": ";

            return($"Got status {err.status} ({err.code}){colonSpace}{err.message}");
        }
Пример #2
0
        /// <summary>
        /// Tries to parse a <see cref="B2Error"/> from the given response.
        /// </summary>
        /// <param name="res">The response that contains an error.</param>
        /// <returns>
        /// The parse result, or null if the response is successful or cannot be parsed.
        /// </returns>
        /// <exception cref="IOException">If the response body cannot be read.</exception>
        private static B2Error ParseB2Error(HttpWebResponse res)
        {
            if (UploadHelpers.IsSuccessfulResponse(res))
            {
                return(null);
            }

            try
            {
                string body = UploadHelpers.ResponseToString(res);
                DebugHelper.WriteLine($"B2 uploader: ParseB2Error() got: {body}");
                B2Error err = JsonConvert.DeserializeObject <B2Error>(body);
                return(err);
            }
            catch (JsonException)
            {
                return(null);
            }
        }
Пример #3
0
 public B2UploadResult(int rc, B2Error error, B2Upload upload)
 {
     RC     = rc;
     Error  = error;
     Upload = upload;
 }
Пример #4
0
 public void Deconstruct(out int rc, out B2Error error, out B2Upload upload)
 {
     rc     = RC;
     error  = Error;
     upload = Upload;
 }