Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
rework exception constructors
  • Loading branch information
annelo-msft committed Jan 5, 2024
commit ffd0b289cfbd24ab6a276625dfd4705c46c2f63b
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ protected ClientResult(System.ClientModel.Primitives.PipelineResponse response)
}
public partial class ClientResultException : System.Exception, System.Runtime.Serialization.ISerializable
{
public ClientResultException(System.ClientModel.Primitives.PipelineResponse response, string? message = null, System.Exception? innerException = null) { }
public ClientResultException(System.ClientModel.Primitives.PipelineResponse response, System.Exception? innerException = null) { }
protected ClientResultException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public ClientResultException(string message, System.Exception? innerException = null) { }
public ClientResultException(string message, System.ClientModel.Primitives.PipelineResponse? response = null, System.Exception? innerException = null) { }
public int Status { get { throw null; } protected set { } }
public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public System.ClientModel.Primitives.PipelineResponse? GetRawResponse() { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ protected ClientResult(System.ClientModel.Primitives.PipelineResponse response)
}
public partial class ClientResultException : System.Exception, System.Runtime.Serialization.ISerializable
{
public ClientResultException(System.ClientModel.Primitives.PipelineResponse response, string? message = null, System.Exception? innerException = null) { }
public ClientResultException(System.ClientModel.Primitives.PipelineResponse response, System.Exception? innerException = null) { }
protected ClientResultException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public ClientResultException(string message, System.Exception? innerException = null) { }
public ClientResultException(string message, System.ClientModel.Primitives.PipelineResponse? response = null, System.Exception? innerException = null) { }
public int Status { get { throw null; } protected set { } }
public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public System.ClientModel.Primitives.PipelineResponse? GetRawResponse() { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.ClientModel.Internal;
using System.ClientModel.Primitives;
using System.Globalization;
using System.IO;
using System.Runtime.Serialization;
using System.Text;

Expand All @@ -27,19 +26,20 @@ public int Status
protected set => _status = value;
}

public ClientResultException(PipelineResponse response, string? message = default, Exception? innerException = default)
: base(GetMessage(response, message), innerException)
public ClientResultException(PipelineResponse response, Exception? innerException = default)
: base(GetMessage(response), innerException)
{
ClientUtilities.AssertNotNull(response, nameof(response));

_response = response;
_status = response.Status;
}

public ClientResultException(string message, Exception? innerException = default)
: base(message, innerException)
public ClientResultException(string message, PipelineResponse? response = default, Exception? innerException = default)
: base(message ?? DefaultMessage, innerException)
{
_status = 0;
_response = response;
_status = response?.Status ?? 0;
}

/// <summary>
Expand All @@ -65,15 +65,8 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont

public PipelineResponse? GetRawResponse() => _response;

// Create message from response if available, and override message, if available.
private static string GetMessage(PipelineResponse response, string? message)
private static string GetMessage(PipelineResponse response)
{
// Setting the message will override extracting it from the response.
if (message is not null)
{
return message;
}

response.BufferContent();

StringBuilder messageBuilder = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void PassingMessageOverridesResponseMessage()
PipelineResponse response = new MockPipelineResponse(200, "MockReason");
string message = "Override Message";

ClientResultException exception = new ClientResultException(response, message);
ClientResultException exception = new ClientResultException(message, response);

Assert.AreEqual(response.Status, exception.Status);
Assert.AreEqual(response, exception.GetRawResponse());
Expand Down