Skip to content

Commit

Permalink
ReFix Set-AzPolicySetDefinition InternalServerError when the initia…
Browse files Browse the repository at this point in the history
…tive is too large [#20238] (#20399)

* Fixed issue introduced in previous fix for `Set-AzPolicySetDefinition` InternalServerError when the initiative is too large [#20238], which will remove space in value.

* avoid unexpected exception in deserilize json string

Co-authored-by: Xuejun Li <[email protected]>
  • Loading branch information
rachelxj-ms and Xuejun Li authored Dec 12, 2022
1 parent c283104 commit 34f9661
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.RestClients
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
Expand Down Expand Up @@ -165,7 +164,18 @@ protected async Task<HttpResponseMessage> SendRequestAsync(
{
var contentString = content == null ? string.Empty : content.ToString();
// minify JOSN payload to avoid payload too large error
contentString = Regex.Replace(contentString, @"\r\n?|\n|\t| ", String.Empty);
if (!string.IsNullOrEmpty(contentString))
{
try
{
var obj = JsonConvert.DeserializeObject(contentString);
contentString = JsonConvert.SerializeObject(obj, Formatting.None);
}
catch
{
// leave contentString as it is
}
}
using (var httpContent = new StringContent(content: contentString, encoding: Encoding.UTF8, mediaType: "application/json"))
using (var request = new HttpRequestMessage(method: httpMethod, requestUri: requestUri) { Content = httpContent })
{
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Resources/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-->

## Upcoming Release
* Fixed issue introduced in previous fix for `Set-AzPolicySetDefinition` InternalServerError when the initiative is too large [#20238], which will remove space in value.

## Version 6.5.0
* Added cmdlet `Get-AzADOrganization`
Expand Down

0 comments on commit 34f9661

Please sign in to comment.