Skip to content

Commit a7b3b3a

Browse files
Addressing code review comments.
1 parent b26c8ec commit a7b3b3a

File tree

4 files changed

+20
-55
lines changed

4 files changed

+20
-55
lines changed

src/ResourceManager/Automation/Commands.Automation/Cmdlet/AzureAutomationBaseCmdlet.cs

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,10 @@ public override void ExecuteCmdlet()
9090
{
9191
if (!string.IsNullOrEmpty(ErrorResponseException.Response.Content))
9292
{
93-
if (IsValidJsonObject(ErrorResponseException.Response.Content))
93+
var message = ParseJson(ErrorResponseException.Response.Content);
94+
if (!string.IsNullOrEmpty(message))
9495
{
95-
var message = ParseJson(ErrorResponseException.Response.Content);
96-
if (!string.IsNullOrEmpty(message))
97-
{
98-
throw new ErrorResponseException(message, ErrorResponseException);
99-
}
96+
throw new ErrorResponseException(message, ErrorResponseException);
10097
}
10198
}
10299
}
@@ -113,7 +110,7 @@ private string ParseJson(string value)
113110
value = value.Trim();
114111
try
115112
{
116-
var nestedError = JsonConvert.DeserializeObject<AzureAutomationNestedErrorResponseMessage>(value);
113+
var nestedError = JsonConvert.DeserializeObject<AzureAutomationErrorResponseMessage>(value);
117114
return nestedError.Error.Message;
118115
}
119116
catch
@@ -123,7 +120,7 @@ private string ParseJson(string value)
123120

124121
try
125122
{
126-
var error = JsonConvert.DeserializeObject<AzureAutomationErrorResponseMessage>(value);
123+
var error = JsonConvert.DeserializeObject<AzureAutomationErrorInfo>(value);
127124
return error.Message;
128125
}
129126
catch
@@ -167,25 +164,5 @@ protected bool GenerateCmdletOutput(IEnumerable<object> results)
167164

168165
return ret;
169166
}
170-
171-
// This function determines if the given value is a Json object.
172-
private bool IsValidJsonObject(string value)
173-
{
174-
value = value.Trim();
175-
if (value.StartsWith("{") && value.EndsWith("}"))
176-
{
177-
try
178-
{
179-
var result = JObject.Parse(value);
180-
return true;
181-
}
182-
catch
183-
{
184-
// ignore the failure
185-
return false;
186-
}
187-
}
188-
return false;
189-
}
190167
}
191168
}

src/ResourceManager/Automation/Commands.Automation/Commands.Automation.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@
148148
<Compile Include="Common\AutomationPSClientSourceControl.cs" />
149149
<Compile Include="Common\AutomationPSClientWebhook.cs" />
150150
<Compile Include="Common\AutomationCmdletParameterSet.cs" />
151-
<Compile Include="Common\AzureAutomationNestedErrorResponseMessage.cs" />
152-
<Compile Include="Common\AzureAutomationOperationException.cs" />
151+
<Compile Include="Common\AzureAutomationErrorInfo.cs" />
153152
<Compile Include="Common\AzureAutomationErrorResponseMessage.cs" />
153+
<Compile Include="Common\AzureAutomationOperationException.cs" />
154154
<Compile Include="Common\Constants.cs" />
155155
<Compile Include="Common\DscNodeStatus.cs" />
156156
<Compile Include="Common\IAutomationPSClient.cs" />
Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,21 @@ namespace Microsoft.Azure.Commands.Automation.Common
1919
/// <summary>
2020
/// The error response message.
2121
/// </summary>
22-
public class AzureAutomationNestedErrorResponseMessage
22+
public class AzureAutomationErrorInfo
2323
{
24-
// Gets or sets the extended error info.
24+
// Gets or sets the error code.
2525
[JsonProperty(Required = Required.Default)]
26-
public AzureAutomationErrorInfo Error { get; set; }
26+
public string Code { get; set; }
2727

28-
// Initializes a new instance of the class.
29-
public AzureAutomationNestedErrorResponseMessage(string code, string message)
30-
{
31-
this.Error = new AzureAutomationErrorInfo { Code = code, Message = message };
32-
}
28+
// Gets or sets the error message.
29+
[JsonProperty(Required = Required.Default)]
30+
public string Message { get; set; }
3331

34-
/// The error information.
35-
public class AzureAutomationErrorInfo
32+
// Initializes a new instance of the class.
33+
public AzureAutomationErrorInfo(string code, string message)
3634
{
37-
// Gets or sets the error code.
38-
[JsonProperty(Required = Required.Default)]
39-
public string Code { get; set; }
40-
41-
// Gets or sets the error message.
42-
[JsonProperty(Required = Required.Default)]
43-
public string Message { get; set; }
35+
this.Code = code;
36+
this.Message = message;
4437
}
4538
}
4639
}

src/ResourceManager/Automation/Commands.Automation/Common/AzureAutomationErrorResponseMessage.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,14 @@ namespace Microsoft.Azure.Commands.Automation.Common
2121
/// </summary>
2222
public class AzureAutomationErrorResponseMessage
2323
{
24-
// Gets or sets the error code.
24+
// Gets or sets the extended error info.
2525
[JsonProperty(Required = Required.Default)]
26-
public string Code { get; set; }
27-
28-
// Gets or sets the error message.
29-
[JsonProperty(Required = Required.Default)]
30-
public string Message { get; set; }
26+
public AzureAutomationErrorInfo Error { get; set; }
3127

3228
// Initializes a new instance of the class.
3329
public AzureAutomationErrorResponseMessage(string code, string message)
3430
{
35-
this.Code = code;
36-
this.Message = message;
31+
this.Error = new AzureAutomationErrorInfo(code, message);
3732
}
3833
}
3934
}

0 commit comments

Comments
 (0)