Skip to content

Commit 4db2071

Browse files
authored
Refine exception definitions (#241)
* refine exception definitions * update
1 parent b267c6a commit 4db2071

File tree

5 files changed

+44
-28
lines changed

5 files changed

+44
-28
lines changed

src/Common/Exceptions/AzPSArgumentException.cs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
using System;
1616
using System.IO;
17+
using System.Management.Automation;
1718
using System.Runtime.CompilerServices;
1819

1920
namespace Microsoft.Azure.Commands.Common.Exceptions
2021
{
21-
public class AzPSArgumentException : ArgumentException, IContainsAzPSErrorData
22+
public class AzPSArgumentException : PSArgumentException, IContainsAzPSErrorData
2223
{
2324
private string ErrorParamName
2425
{
@@ -53,23 +54,21 @@ public string ErrorFileName
5354
public AzPSArgumentException(
5455
string message,
5556
string paramName,
56-
Exception innerException = null,
5757
string desensitizedMessage = null,
5858
[CallerLineNumber] int lineNumber = 0,
5959
[CallerFilePath] string filePath = null)
60-
: this(message, paramName, ErrorKind.UserError, innerException, desensitizedMessage, lineNumber, filePath)
60+
: this(message, paramName, ErrorKind.UserError, desensitizedMessage, lineNumber, filePath)
6161
{
6262
}
6363

6464
public AzPSArgumentException(
6565
string message,
6666
string paramName,
6767
ErrorKind errorKind,
68-
Exception innerException = null,
6968
string desensitizedMessage = null,
7069
[CallerLineNumber] int lineNumber = 0,
7170
[CallerFilePath] string filePath = null)
72-
:base(message, paramName, innerException)
71+
:base(message, paramName)
7372
{
7473
ErrorParamName = paramName;
7574
ErrorKind = errorKind;
@@ -81,5 +80,34 @@ public AzPSArgumentException(
8180
ErrorFileName = Path.GetFileNameWithoutExtension(filePath);
8281
}
8382
}
83+
84+
public AzPSArgumentException(
85+
string message,
86+
Exception innerException,
87+
string desensitizedMessage = null,
88+
[CallerLineNumber] int lineNumber = 0,
89+
[CallerFilePath] string filePath = null)
90+
: this(message, innerException, ErrorKind.UserError, desensitizedMessage, lineNumber, filePath)
91+
{
92+
}
93+
94+
public AzPSArgumentException(
95+
string message,
96+
Exception innerException,
97+
ErrorKind errorKind,
98+
string desensitizedMessage = null,
99+
[CallerLineNumber] int lineNumber = 0,
100+
[CallerFilePath] string filePath = null)
101+
: base(message, innerException)
102+
{
103+
ErrorKind = errorKind;
104+
DesensitizedErrorMessage = desensitizedMessage;
105+
ErrorLineNumber = lineNumber;
106+
107+
if (!string.IsNullOrEmpty(filePath))
108+
{
109+
ErrorFileName = Path.GetFileNameWithoutExtension(filePath);
110+
}
111+
}
84112
}
85113
}

src/Common/Exceptions/AzPSArgumentNullException.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
using System;
1616
using System.IO;
17+
using System.Management.Automation;
1718
using System.Runtime.CompilerServices;
1819

1920
namespace Microsoft.Azure.Commands.Common.Exceptions
2021
{
21-
public class AzPSArgumentNullException : ArgumentNullException, IContainsAzPSErrorData
22+
public class AzPSArgumentNullException : PSArgumentNullException, IContainsAzPSErrorData
2223
{
2324
private string ErrorParamName
2425
{

src/Common/Exceptions/AzPSArgumentOutOfRangeException.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
using System;
1616
using System.IO;
17+
using System.Management.Automation;
1718
using System.Runtime.CompilerServices;
1819

1920
namespace Microsoft.Azure.Commands.Common.Exceptions
2021
{
21-
public class AzPSArgumentOutOfRangeException : ArgumentOutOfRangeException, IContainsAzPSErrorData
22+
public class AzPSArgumentOutOfRangeException : PSArgumentOutOfRangeException, IContainsAzPSErrorData
2223
{
2324
private string ErrorParamName
2425
{

src/Common/Exceptions/AzPSCloudException.cs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,21 @@
2121

2222
namespace Microsoft.Azure.Commands.Common.Exceptions
2323
{
24-
public class AzPSCloudException : Exception, IContainsAzPSErrorData
24+
public class AzPSCloudException : CloudException, IContainsAzPSErrorData
2525
{
26-
private HttpResponseMessageWrapper httpResponseMessageWrapper;
27-
28-
public HttpRequestMessageWrapper Request { get; set; }
29-
3026
/// <summary>
3127
/// Gets information about the associated HTTP response.
3228
/// </summary>
33-
public HttpResponseMessageWrapper Response
29+
public new HttpResponseMessageWrapper Response
3430
{
35-
get { return httpResponseMessageWrapper; }
31+
get { return base.Response; }
3632
set
3733
{
38-
httpResponseMessageWrapper = value;
39-
HttpStatusCode = (int?)httpResponseMessageWrapper?.StatusCode;
34+
base.Response = value;
35+
HttpStatusCode = (int?)value?.StatusCode;
4036
}
4137
}
4238

43-
/// <summary>
44-
/// Gets or sets the response object.
45-
/// </summary>
46-
public CloudError Body { get; set; }
47-
48-
/// <summary>
49-
/// Gets or sets the value that uniquely identifies a request
50-
/// made against the service.
51-
/// </summary>
52-
public string RequestId { get; set; }
53-
5439
public ErrorKind ErrorKind
5540
{
5641
get => Data.GetValue<ErrorKind>(AzurePSErrorDataKeys.ErrorKindKey);

src/Common/Exceptions/AzPSInvalidOperationException.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
using System;
1616
using System.IO;
17+
using System.Management.Automation;
1718
using System.Runtime.CompilerServices;
1819

1920
namespace Microsoft.Azure.Commands.Common.Exceptions
2021
{
21-
public class AzPSInvalidOperationException : InvalidOperationException, IContainsAzPSErrorData
22+
public class AzPSInvalidOperationException : PSInvalidOperationException, IContainsAzPSErrorData
2223
{
2324
public ErrorKind ErrorKind
2425
{

0 commit comments

Comments
 (0)