| | 1 | | // Copyright (c) Microsoft. All rights reserved. |
| | 2 | | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| | 3 | |
|
| | 4 | | namespace Microsoft.Azure.ServiceBus |
| | 5 | | { |
| | 6 | | using System; |
| | 7 | | using Primitives; |
| | 8 | |
|
| | 9 | | /// <summary> |
| | 10 | | /// Base Exception for various Service Bus errors. |
| | 11 | | /// </summary> |
| | 12 | | public class ServiceBusException : Exception |
| | 13 | | { |
| | 14 | | /// <summary> |
| | 15 | | /// Returns a new ServiceBusException |
| | 16 | | /// </summary> |
| | 17 | | /// <param name="isTransient">Specifies whether or not the exception is transient.</param> |
| 0 | 18 | | public ServiceBusException(bool isTransient) |
| | 19 | | { |
| 0 | 20 | | this.IsTransient = isTransient; |
| 0 | 21 | | } |
| | 22 | |
|
| | 23 | | /// <summary> |
| | 24 | | /// Returns a new ServiceBusException |
| | 25 | | /// </summary> |
| | 26 | | /// <param name="isTransient">Specifies whether or not the exception is transient.</param> |
| | 27 | | /// <param name="message">The detailed message exception.</param> |
| | 28 | | public ServiceBusException(bool isTransient, string message) |
| 4 | 29 | | : base(message) |
| | 30 | | { |
| 4 | 31 | | this.IsTransient = isTransient; |
| 4 | 32 | | } |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// Returns a new ServiceBusException |
| | 36 | | /// </summary> |
| | 37 | | /// <param name="isTransient">Specifies whether or not the exception is transient.</param> |
| | 38 | | public ServiceBusException(bool isTransient, Exception innerException) |
| 0 | 39 | | : base(innerException.Message, innerException) |
| | 40 | | { |
| 0 | 41 | | this.IsTransient = isTransient; |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | /// <summary> |
| | 45 | | /// Returns a new ServiceBusException |
| | 46 | | /// </summary> |
| | 47 | | /// <param name="isTransient">Specifies whether or not the exception is transient.</param> |
| | 48 | | /// <param name="message">The detailed message exception.</param> |
| | 49 | | public ServiceBusException(bool isTransient, string message, Exception innerException) |
| 26 | 50 | | : base(message, innerException) |
| | 51 | | { |
| 26 | 52 | | this.IsTransient = isTransient; |
| 26 | 53 | | } |
| | 54 | |
|
| | 55 | | /// <summary> |
| | 56 | | /// Gets the message as a formatted string. |
| | 57 | | /// </summary> |
| | 58 | | public override string Message |
| | 59 | | { |
| | 60 | | get |
| | 61 | | { |
| 34 | 62 | | var baseMessage = base.Message; |
| 34 | 63 | | if (string.IsNullOrEmpty(this.ServiceBusNamespace)) |
| | 64 | | { |
| 34 | 65 | | return baseMessage; |
| | 66 | | } |
| | 67 | |
|
| 0 | 68 | | return "{0}, ({1})".FormatInvariant(baseMessage, this.ServiceBusNamespace); |
| | 69 | | } |
| | 70 | | } |
| | 71 | |
|
| | 72 | | /// <summary> |
| | 73 | | /// A boolean indicating if the exception is a transient error or not. |
| | 74 | | /// </summary> |
| | 75 | | /// <value>returns true when user can retry the operation that generated the exception without additional interv |
| 82 | 76 | | public bool IsTransient { get; } |
| | 77 | |
|
| | 78 | | /// <summary> |
| | 79 | | /// Gets the Service Bus namespace from which the exception occurred, if available. |
| | 80 | | /// </summary> |
| 0 | 81 | | public string ServiceBusNamespace { get; internal set; } |
| | 82 | | } |
| | 83 | | } |