| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | namespace Azure.Messaging.EventHubs.Core |
| | 5 | | { |
| | 6 | | /// <summary> |
| | 7 | | /// The set of extension methods for the <see cref="EventHubsException" /> class. |
| | 8 | | /// </summary> |
| | 9 | | /// |
| | 10 | | internal static class EventHubsExceptionExtensions |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// The key to fetch the data FailureData value from the exception Data property. |
| | 14 | | /// </summary> |
| | 15 | | private const string FailureDataKey = "FailureData"; |
| | 16 | |
|
| | 17 | | /// <summary> |
| | 18 | | /// The key to fetch the data FailureOperation value from the exception Data property. |
| | 19 | | /// </summary> |
| | 20 | | private const string FailureOperationKey = "FailureOperation"; |
| | 21 | |
|
| | 22 | | /// <summary> |
| | 23 | | /// Gets the data value related to the exception <see cref="EventHubsException.FailureReason" />. |
| | 24 | | /// </summary> |
| | 25 | | /// |
| | 26 | | /// <param name="instance">The instance that this method was invoked on.</param> |
| | 27 | | /// |
| | 28 | | /// <returns>The Data value or null.</returns> |
| | 29 | | /// |
| | 30 | | public static T GetFailureData<T>(this EventHubsException instance) where T : class => |
| 0 | 31 | | instance.Data.Contains(FailureDataKey) ? |
| 0 | 32 | | instance.Data[FailureDataKey] as T : |
| 0 | 33 | | null; |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// Gets the failed operation name related to the exception. |
| | 37 | | /// </summary> |
| | 38 | | /// |
| | 39 | | /// <param name="instance">The instance that this method was invoked on.</param> |
| | 40 | | /// |
| | 41 | | /// <returns>The failed operation name.</returns> |
| | 42 | | /// |
| | 43 | | public static string GetFailureOperation(this EventHubsException instance) => |
| 0 | 44 | | instance.Data.Contains(FailureOperationKey) ? |
| 0 | 45 | | instance.Data[FailureOperationKey] as string : |
| 0 | 46 | | string.Empty; |
| | 47 | |
|
| | 48 | | /// <summary> |
| | 49 | | /// Sets the data value related to the exception. |
| | 50 | | /// </summary> |
| | 51 | | /// |
| | 52 | | /// <param name="instance">The instance that this method was invoked on.</param> |
| | 53 | | /// <param name="data">The value to store in the Exception Data.</param> |
| | 54 | | /// |
| | 55 | | public static void SetFailureData<T>(this EventHubsException instance, T data) where T : class => |
| 0 | 56 | | instance.Data[FailureDataKey] = data; |
| | 57 | |
|
| | 58 | | /// <summary> |
| | 59 | | /// Sets the failed operation name related to the exception. |
| | 60 | | /// </summary> |
| | 61 | | /// |
| | 62 | | /// <param name="instance">The instance that this method was invoked on.</param> |
| | 63 | | /// <param name="operationName">The failed operation name.</param> |
| | 64 | | /// |
| | 65 | | public static void SetFailureOperation(this EventHubsException instance, string operationName) => |
| 0 | 66 | | instance.Data[FailureOperationKey] = operationName; |
| | 67 | | } |
| | 68 | | } |