Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions src/Common/Exceptions/AzPSArgumentException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -53,23 +54,21 @@ 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)
{
}

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;
Expand All @@ -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);
}
}
}
}
3 changes: 2 additions & 1 deletion src/Common/Exceptions/AzPSArgumentNullException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Common/Exceptions/AzPSArgumentOutOfRangeException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
25 changes: 5 additions & 20 deletions src/Common/Exceptions/AzPSCloudException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

/// <summary>
/// Gets information about the associated HTTP response.
/// </summary>
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;
}
}

/// <summary>
/// Gets or sets the response object.
/// </summary>
public CloudError Body { get; set; }

/// <summary>
/// Gets or sets the value that uniquely identifies a request
/// made against the service.
/// </summary>
public string RequestId { get; set; }

public ErrorKind ErrorKind
{
get => Data.GetValue<ErrorKind>(AzurePSErrorDataKeys.ErrorKindKey);
Expand Down
3 changes: 2 additions & 1 deletion src/Common/Exceptions/AzPSInvalidOperationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down