/// <summary> /// Tries to translate the specified exception into a storage exception. /// </summary> /// <param name="ex">The exception to translate.</param> /// <param name="reqResult">The request result.</param> /// <param name="parseError">The delegate used to parse the error to get extended error information.</param> /// <returns>The storage exception or <c>null</c>.</returns> private static StorageException CoreTranslate(Exception ex, RequestResult reqResult, ref Func <Stream, StorageExtendedErrorInformation> parseError) { CommonUtility.AssertNotNull("reqResult", reqResult); CommonUtility.AssertNotNull("ex", ex); if (parseError == null) { parseError = s => StorageExtendedErrorInformation.ReadFromStreamAsync(s).GetAwaiter().GetResult(); } // Dont re-wrap storage exceptions if (ex is StorageException) { return((StorageException)ex); } else if (ex is TimeoutException) { reqResult.HttpStatusMessage = null; reqResult.HttpStatusCode = (int)HttpStatusCode.RequestTimeout; reqResult.ExtendedErrorInformation = null; return(new StorageException(reqResult, ex.Message, ex)); } else if (ex is ArgumentException) { reqResult.HttpStatusMessage = null; reqResult.HttpStatusCode = (int)HttpStatusCode.Unused; reqResult.ExtendedErrorInformation = null; return(new StorageException(reqResult, ex.Message, ex) { IsRetryable = false }); } // return null and check in the caller return(null); }
/// <summary> /// Translates the specified exception into a storage exception. /// </summary> /// <param name="ex">The exception to translate.</param> /// <param name="reqResult">The request result.</param> /// <param name="parseError">The delegate used to parse the error to get extended error information.</param> /// <param name="responseStream">The error stream that contains the error information.</param> /// <param name="response">HTTP response message</param> /// <returns>The storage exception.</returns> internal static StorageException TranslateExceptionWithPreBufferedStream(Exception ex, RequestResult reqResult, Func <Stream, StorageExtendedErrorInformation> parseError, Stream responseStream, HttpResponseMessage response) { StorageException storageException; try { if ((storageException = CoreTranslate(ex, reqResult, ref parseError)) != null) { return(storageException); } if (response != null) { PopulateRequestResult(reqResult, response); reqResult.ExtendedErrorInformation = StorageExtendedErrorInformation.ReadFromStreamAsync(responseStream).GetAwaiter().GetResult(); } } catch (Exception) { // if there is an error thrown while parsing the service error, just wrap the service error in a StorageException. // no op } // Just wrap in StorageException return(new StorageException(reqResult, ex.Message, ex)); }