Skip to content

Commit 8a00ab3

Browse files
committed
add custom error handler
1 parent cc100ad commit 8a00ab3

9 files changed

+176
-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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 errorResponse = errorResponseTask?.ConfigureAwait(false).GetAwaiter().GetResult();
16+
17+
if (errorResponse?.Detail != null && errorResponse?.Detail.Count > 0)
18+
{
19+
var errorDetails = errorResponse.Detail;
20+
var errorDetailsString = "";
21+
22+
foreach (var errorDetail in errorDetails)
23+
{
24+
errorDetailsString += errorDetail.Message + " ";
25+
}
26+
27+
cmdlet.WriteError(new ErrorRecord(new System.Exception(), null, ErrorCategory.InvalidOperation, null)
28+
{
29+
ErrorDetails = new ErrorDetails(errorDetailsString) { RecommendedAction = string.Empty }
30+
});
31+
32+
returnNow = Task.FromResult(true);
33+
}
34+
else
35+
{
36+
returnNow = Task.FromResult(false);
37+
}
38+
}
39+
}
40+
}
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)