/// <summary> /// Create an exception corresponding to the StorageError. /// </summary> /// <param name="clientDiagnostics">The <see cref="ClientDiagnostics"/> instance to use.</param> /// <param name="response">The failed response.</param> /// <returns> /// A <see cref="RequestFailedException"/>. /// </returns> public Exception CreateException(ClientDiagnostics clientDiagnostics, Azure.Response response) => clientDiagnostics.CreateRequestFailedExceptionWithContent( response, message: Message, content: null, response.GetErrorCode(Code), AdditionalInformation);
// clientDiagnostics parameter is a pattern expected by the codegenerator #pragma warning disable CA1801 internal static Exception CreateException(this string jsonMessage, ClientDiagnostics clientDiagnostics, Response response) #pragma warning restore CA1801 { if (string.IsNullOrWhiteSpace(jsonMessage)) { return(new RequestFailedException( status: response.Status, errorCode: response.Status.ToString(CultureInfo.InvariantCulture), message: response.ReasonPhrase, innerException: new Exception())); } else { JsonDocument json = JsonDocument.Parse(jsonMessage); JsonElement error = json.RootElement.GetProperty("error"); IDictionary <string, string> details = default; if (error.TryGetProperty("detail", out JsonElement detail)) { details = new Dictionary <string, string>(); foreach (JsonProperty property in detail.EnumerateObject()) { details[property.Name] = property.Value.GetString(); } } return(clientDiagnostics.CreateRequestFailedExceptionWithContent( response: response, message: error.GetProperty("message").GetString(), errorCode: error.GetProperty("code").GetString(), additionalInfo: details)); } }
// clientDiagnostics parameter is a pattern expected by the codegenerator #pragma warning disable CA1801 internal static Exception CreateException(this string body, ClientDiagnostics clientDiagnostics, Response response) #pragma warning restore CA1801 { // xml if (response.Headers.ContentType != null && response.Headers.ContentType.Contains("application/xml")) { XElement error = XDocument.Parse(body).Element("Error"); string code = error.Element("Code").Value.ToString(CultureInfo.InvariantCulture); string message = error.Element("Message").Value.ToString(CultureInfo.InvariantCulture); return(clientDiagnostics.CreateRequestFailedExceptionWithContent( response: response, message: message, errorCode: code)); } // json else if (response.Headers.ContentType != null && response.Headers.ContentType.Contains("application/json")) { JsonDocument json = JsonDocument.Parse(body); JsonElement error = json.RootElement.GetProperty("error"); IDictionary <string, string> details = default; if (error.TryGetProperty("detail", out JsonElement detail)) { details = new Dictionary <string, string>(); foreach (JsonProperty property in detail.EnumerateObject()) { details[property.Name] = property.Value.GetString(); } } return(clientDiagnostics.CreateRequestFailedExceptionWithContent( response: response, message: error.GetProperty("message").GetString(), errorCode: error.GetProperty("code").GetString(), additionalInfo: details)); } else { return(new RequestFailedException( status: response.Status, errorCode: response.Status.ToString(CultureInfo.InvariantCulture), message: response.ReasonPhrase, innerException: new Exception())); } }
/// <summary> /// Create an exception corresponding to the FailureNoContent. /// </summary> /// <param name="clientDiagnostics">The <see cref="ClientDiagnostics"/> instance to use.</param> /// <param name="response">The failed response.</param> /// <returns>A RequestFailedException.</returns> public Exception CreateException(ClientDiagnostics clientDiagnostics, Azure.Response response) => clientDiagnostics.CreateRequestFailedExceptionWithContent( response, message: null, content: null, response.GetErrorCode(ErrorCode));
public static RequestFailedException ClientRequestIdMismatch(ClientDiagnostics clientDiagnostics, Response response, string echo, string original) => clientDiagnostics.CreateRequestFailedExceptionWithContent( response, $"Response x-ms-client-request-id '{echo}' does not match the original expected request id, '{original}'.", errorCode: response.GetErrorCode(null));
public static RequestFailedException InvalidResponse(ClientDiagnostics clientDiagnostics, Response response, Exception innerException) => clientDiagnostics.CreateRequestFailedExceptionWithContent(response, message: "Invalid response", innerException: innerException);
/// <summary> /// Create an exception corresponding to the DataLakeStorageError. /// </summary> /// <param name="clientDiagnostics">The <see cref="ClientDiagnostics"/> instance to use.</param> /// <param name="response">The failed response.</param> /// <returns>A RequestFailedException.</returns> public Exception CreateException(ClientDiagnostics clientDiagnostics, Azure.Response response) => clientDiagnostics.CreateRequestFailedExceptionWithContent(response, message: DataLakeStorageErrorDetails.Message, content: null, response.GetErrorCode(DataLakeStorageErrorDetails.Code));