diff --git a/src/Common/Exceptions/AzPSArgumentException.cs b/src/Common/Exceptions/AzPSArgumentException.cs
index f81bdf0e1f..c85a9636cf 100644
--- a/src/Common/Exceptions/AzPSArgumentException.cs
+++ b/src/Common/Exceptions/AzPSArgumentException.cs
@@ -14,11 +14,12 @@
using System;
using System.IO;
+using System.Management.Automation;
using System.Runtime.CompilerServices;
namespace Microsoft.Azure.Commands.Common.Exceptions
{
- public class AzPSArgumentException : ArgumentException, IContainsAzPSErrorData
+ public class AzPSArgumentException : PSArgumentException, IContainsAzPSErrorData
{
private string ErrorParamName
{
@@ -53,11 +54,10 @@ public string ErrorFileName
public AzPSArgumentException(
string message,
string paramName,
- Exception innerException = null,
string desensitizedMessage = null,
[CallerLineNumber] int lineNumber = 0,
[CallerFilePath] string filePath = null)
- : this(message, paramName, ErrorKind.UserError, innerException, desensitizedMessage, lineNumber, filePath)
+ : this(message, paramName, ErrorKind.UserError, desensitizedMessage, lineNumber, filePath)
{
}
@@ -65,11 +65,10 @@ public AzPSArgumentException(
string message,
string paramName,
ErrorKind errorKind,
- Exception innerException = null,
string desensitizedMessage = null,
[CallerLineNumber] int lineNumber = 0,
[CallerFilePath] string filePath = null)
- :base(message, paramName, innerException)
+ :base(message, paramName)
{
ErrorParamName = paramName;
ErrorKind = errorKind;
@@ -81,5 +80,34 @@ public AzPSArgumentException(
ErrorFileName = Path.GetFileNameWithoutExtension(filePath);
}
}
+
+ public AzPSArgumentException(
+ string message,
+ Exception innerException,
+ string desensitizedMessage = null,
+ [CallerLineNumber] int lineNumber = 0,
+ [CallerFilePath] string filePath = null)
+ : this(message, innerException, ErrorKind.UserError, desensitizedMessage, lineNumber, filePath)
+ {
+ }
+
+ public AzPSArgumentException(
+ string message,
+ Exception innerException,
+ ErrorKind errorKind,
+ string desensitizedMessage = null,
+ [CallerLineNumber] int lineNumber = 0,
+ [CallerFilePath] string filePath = null)
+ : base(message, innerException)
+ {
+ ErrorKind = errorKind;
+ DesensitizedErrorMessage = desensitizedMessage;
+ ErrorLineNumber = lineNumber;
+
+ if (!string.IsNullOrEmpty(filePath))
+ {
+ ErrorFileName = Path.GetFileNameWithoutExtension(filePath);
+ }
+ }
}
}
diff --git a/src/Common/Exceptions/AzPSArgumentNullException.cs b/src/Common/Exceptions/AzPSArgumentNullException.cs
index e6585dbb58..a2ea50e4f6 100644
--- a/src/Common/Exceptions/AzPSArgumentNullException.cs
+++ b/src/Common/Exceptions/AzPSArgumentNullException.cs
@@ -14,11 +14,12 @@
using System;
using System.IO;
+using System.Management.Automation;
using System.Runtime.CompilerServices;
namespace Microsoft.Azure.Commands.Common.Exceptions
{
- public class AzPSArgumentNullException : ArgumentNullException, IContainsAzPSErrorData
+ public class AzPSArgumentNullException : PSArgumentNullException, IContainsAzPSErrorData
{
private string ErrorParamName
{
diff --git a/src/Common/Exceptions/AzPSArgumentOutOfRangeException.cs b/src/Common/Exceptions/AzPSArgumentOutOfRangeException.cs
index 90bd339bc0..489ca72630 100644
--- a/src/Common/Exceptions/AzPSArgumentOutOfRangeException.cs
+++ b/src/Common/Exceptions/AzPSArgumentOutOfRangeException.cs
@@ -14,11 +14,12 @@
using System;
using System.IO;
+using System.Management.Automation;
using System.Runtime.CompilerServices;
namespace Microsoft.Azure.Commands.Common.Exceptions
{
- public class AzPSArgumentOutOfRangeException : ArgumentOutOfRangeException, IContainsAzPSErrorData
+ public class AzPSArgumentOutOfRangeException : PSArgumentOutOfRangeException, IContainsAzPSErrorData
{
private string ErrorParamName
{
diff --git a/src/Common/Exceptions/AzPSCloudException.cs b/src/Common/Exceptions/AzPSCloudException.cs
index ecd8cc9e95..16120478f6 100644
--- a/src/Common/Exceptions/AzPSCloudException.cs
+++ b/src/Common/Exceptions/AzPSCloudException.cs
@@ -21,36 +21,21 @@
namespace Microsoft.Azure.Commands.Common.Exceptions
{
- public class AzPSCloudException : Exception, IContainsAzPSErrorData
+ public class AzPSCloudException : CloudException, IContainsAzPSErrorData
{
- private HttpResponseMessageWrapper httpResponseMessageWrapper;
-
- public HttpRequestMessageWrapper Request { get; set; }
-
///
/// Gets information about the associated HTTP response.
///
- public HttpResponseMessageWrapper Response
+ public new HttpResponseMessageWrapper Response
{
- get { return httpResponseMessageWrapper; }
+ get { return base.Response; }
set
{
- httpResponseMessageWrapper = value;
- HttpStatusCode = (int?)httpResponseMessageWrapper?.StatusCode;
+ base.Response = value;
+ HttpStatusCode = (int?)value?.StatusCode;
}
}
- ///
- /// Gets or sets the response object.
- ///
- public CloudError Body { get; set; }
-
- ///
- /// Gets or sets the value that uniquely identifies a request
- /// made against the service.
- ///
- public string RequestId { get; set; }
-
public ErrorKind ErrorKind
{
get => Data.GetValue(AzurePSErrorDataKeys.ErrorKindKey);
diff --git a/src/Common/Exceptions/AzPSInvalidOperationException.cs b/src/Common/Exceptions/AzPSInvalidOperationException.cs
index f85235846e..bdefd0dfd8 100644
--- a/src/Common/Exceptions/AzPSInvalidOperationException.cs
+++ b/src/Common/Exceptions/AzPSInvalidOperationException.cs
@@ -14,11 +14,12 @@
using System;
using System.IO;
+using System.Management.Automation;
using System.Runtime.CompilerServices;
namespace Microsoft.Azure.Commands.Common.Exceptions
{
- public class AzPSInvalidOperationException : InvalidOperationException, IContainsAzPSErrorData
+ public class AzPSInvalidOperationException : PSInvalidOperationException, IContainsAzPSErrorData
{
public ErrorKind ErrorKind
{