Skip to content

Commit 615e1c5

Browse files
authored
Add custom error handling for New- and Update- cmdlets to print full details of error (#9)
* Add custom error handler
1 parent 8e5227f commit 615e1c5

9 files changed

+160
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System.Net.Http;
5+
using System.Threading.Tasks;
6+
using Microsoft.Azure.PowerShell.Cmdlets.Support.Models;
7+
8+
namespace Microsoft.Azure.PowerShell.Cmdlets.Support.Cmdlets
9+
{
10+
public partial class NewAzSupportCommunication_CreateExpanded
11+
{
12+
partial void overrideOnDefault(HttpResponseMessage responseMessage, Task<IErrorResponse> errorResponseTask, ref Task<bool> returnNow)
13+
{
14+
this.WriteError(responseMessage, errorResponseTask, ref returnNow);
15+
}
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System.Net.Http;
5+
using System.Threading.Tasks;
6+
using Microsoft.Azure.PowerShell.Cmdlets.Support.Models;
7+
8+
namespace Microsoft.Azure.PowerShell.Cmdlets.Support.Cmdlets
9+
{
10+
public partial class NewAzSupportCommunicationsNoSubscription_CreateExpanded
11+
{
12+
partial void overrideOnDefault(HttpResponseMessage responseMessage, Task<IErrorResponse> errorResponseTask, ref Task<bool> returnNow)
13+
{
14+
this.WriteError(responseMessage, errorResponseTask, ref returnNow);
15+
}
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System.Net.Http;
5+
using System.Threading.Tasks;
6+
using Microsoft.Azure.PowerShell.Cmdlets.Support.Models;
7+
8+
namespace Microsoft.Azure.PowerShell.Cmdlets.Support.Cmdlets
9+
{
10+
public partial class NewAzSupportTicket_CreateExpanded
11+
{
12+
partial void overrideOnDefault(HttpResponseMessage responseMessage, Task<IErrorResponse> errorResponseTask, ref Task<bool> returnNow)
13+
{
14+
this.WriteError(responseMessage, errorResponseTask, ref returnNow);
15+
}
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System.Net.Http;
5+
using System.Threading.Tasks;
6+
using Microsoft.Azure.PowerShell.Cmdlets.Support.Models;
7+
8+
namespace Microsoft.Azure.PowerShell.Cmdlets.Support.Cmdlets
9+
{
10+
public partial class NewAzSupportTicketsNoSubscription_CreateExpanded
11+
{
12+
partial void overrideOnDefault(HttpResponseMessage responseMessage, Task<IErrorResponse> errorResponseTask, ref Task<bool> returnNow)
13+
{
14+
this.WriteError(responseMessage, errorResponseTask, ref returnNow);
15+
}
16+
}
17+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System.Management.Automation;
5+
using System.Net.Http;
6+
using System.Threading.Tasks;
7+
using Microsoft.Azure.PowerShell.Cmdlets.Support.Models;
8+
9+
namespace Microsoft.Azure.PowerShell.Cmdlets.Support.Cmdlets
10+
{
11+
internal static class CmdletRestExtension
12+
{
13+
public static void WriteError(this Cmdlet cmdlet, HttpResponseMessage responseMessage, Task<IErrorResponse> errorResponseTask, ref Task<bool> returnNow)
14+
{
15+
var errorString = responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult();
16+
cmdlet.WriteError(new ErrorRecord(new System.Exception(), null, ErrorCategory.InvalidOperation, null)
17+
{
18+
ErrorDetails = new ErrorDetails(errorString) { RecommendedAction = string.Empty }
19+
});
20+
21+
returnNow = Task.FromResult(true);
22+
}
23+
}
24+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System.Net.Http;
5+
using System.Threading.Tasks;
6+
using Microsoft.Azure.PowerShell.Cmdlets.Support.Models;
7+
8+
namespace Microsoft.Azure.PowerShell.Cmdlets.Support.Cmdlets
9+
{
10+
public partial class UpdateAzSupportTicket_UpdateExpanded
11+
{
12+
partial void overrideOnDefault(HttpResponseMessage responseMessage, Task<IErrorResponse> errorResponseTask, ref Task<bool> returnNow)
13+
{
14+
this.WriteError(responseMessage, errorResponseTask, ref returnNow);
15+
}
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System.Net.Http;
5+
using System.Threading.Tasks;
6+
using Microsoft.Azure.PowerShell.Cmdlets.Support.Models;
7+
8+
namespace Microsoft.Azure.PowerShell.Cmdlets.Support.Cmdlets
9+
{
10+
public partial class UpdateAzSupportTicket_UpdateViaIdentityExpanded
11+
{
12+
partial void overrideOnDefault(HttpResponseMessage responseMessage, Task<IErrorResponse> errorResponseTask, ref Task<bool> returnNow)
13+
{
14+
this.WriteError(responseMessage, errorResponseTask, ref returnNow);
15+
}
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System.Net.Http;
5+
using System.Threading.Tasks;
6+
using Microsoft.Azure.PowerShell.Cmdlets.Support.Models;
7+
8+
namespace Microsoft.Azure.PowerShell.Cmdlets.Support.Cmdlets
9+
{
10+
public partial class UpdateAzSupportTicketsNoSubscription_UpdateExpanded
11+
{
12+
partial void overrideOnDefault(HttpResponseMessage responseMessage, Task<IErrorResponse> errorResponseTask, ref Task<bool> returnNow)
13+
{
14+
this.WriteError(responseMessage, errorResponseTask, ref returnNow);
15+
}
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System.Net.Http;
5+
using System.Threading.Tasks;
6+
using Microsoft.Azure.PowerShell.Cmdlets.Support.Models;
7+
8+
namespace Microsoft.Azure.PowerShell.Cmdlets.Support.Cmdlets
9+
{
10+
public partial class UpdateAzSupportTicketsNoSubscription_UpdateViaIdentityExpanded
11+
{
12+
partial void overrideOnDefault(HttpResponseMessage responseMessage, Task<IErrorResponse> errorResponseTask, ref Task<bool> returnNow)
13+
{
14+
this.WriteError(responseMessage, errorResponseTask, ref returnNow);
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)