From 2edd5555bc19cece6a0a9d955aad6c8f5f1ca709 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Wed, 17 Jan 2024 16:21:43 -0800 Subject: [PATCH] Add protection against empty response from server (#1525) --- src/code/NuGetServerAPICalls.cs | 104 +++++++------ src/code/V2ServerAPICalls.cs | 165 +++++++++++---------- src/code/V3ServerAPICalls.cs | 255 +++++++++++++++++--------------- 3 files changed, 282 insertions(+), 242 deletions(-) diff --git a/src/code/NuGetServerAPICalls.cs b/src/code/NuGetServerAPICalls.cs index 7748695c6..84f376399 100644 --- a/src/code/NuGetServerAPICalls.cs +++ b/src/code/NuGetServerAPICalls.cs @@ -143,9 +143,9 @@ public override FindResults FindTags(string[] tags, bool includePrerelease, Reso public override FindResults FindCommandOrDscResource(string[] tags, bool includePrerelease, bool isSearchingForCommands, out ErrorRecord errRecord) { errRecord = new ErrorRecord( - new InvalidOperationException($"Find by CommandName or DSCResource is not supported for the repository '{Repository.Name}'"), - "FindCommandOrDscResourceFailure", - ErrorCategory.InvalidOperation, + new InvalidOperationException($"Find by CommandName or DSCResource is not supported for the repository '{Repository.Name}'"), + "FindCommandOrDscResourceFailure", + ErrorCategory.InvalidOperation, this); return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: FindResponseType); @@ -431,25 +431,25 @@ private string HttpRequestCall(string requestUrl, out ErrorRecord errRecord) catch (HttpRequestException e) { errRecord = new ErrorRecord( - exception: e, - "HttpRequestFallFailure", - ErrorCategory.ConnectionError, + exception: e, + "HttpRequestFallFailure", + ErrorCategory.ConnectionError, this); } catch (ArgumentNullException e) { errRecord = new ErrorRecord( - exception: e, - "HttpRequestFallFailure", + exception: e, + "HttpRequestFallFailure", ErrorCategory.ConnectionError, this); } catch (InvalidOperationException e) { errRecord = new ErrorRecord( - exception: e, - "HttpRequestFallFailure", - ErrorCategory.ConnectionError, + exception: e, + "HttpRequestFallFailure", + ErrorCategory.ConnectionError, this); } @@ -480,25 +480,25 @@ private HttpContent HttpRequestCallForContent(string requestUrl, out ErrorRecord catch (HttpRequestException e) { errRecord = new ErrorRecord( - exception: e, - "HttpRequestFailure", - ErrorCategory.ConnectionError , + exception: e, + "HttpRequestFailure", + ErrorCategory.ConnectionError , this); } catch (ArgumentNullException e) { errRecord = new ErrorRecord( - exception: e, - "HttpRequestFailure", - ErrorCategory.InvalidData, + exception: e, + "HttpRequestFailure", + ErrorCategory.InvalidData, this); } catch (InvalidOperationException e) { errRecord = new ErrorRecord( - exception: e, - "HttpRequestFailure", - ErrorCategory.InvalidOperation, + exception: e, + "HttpRequestFailure", + ErrorCategory.InvalidOperation, this); } @@ -565,9 +565,9 @@ private string FindNameGlobbing(string packageName, bool includePrerelease, int if (names.Length == 0) { errRecord = new ErrorRecord( - new ArgumentException("-Name '*' for NuGet.Server hosted feed repository is not supported"), - "FindNameGlobbingFailure", - ErrorCategory.InvalidArgument, + new ArgumentException("-Name '*' for NuGet.Server hosted feed repository is not supported"), + "FindNameGlobbingFailure", + ErrorCategory.InvalidArgument, this); return string.Empty; @@ -601,9 +601,9 @@ private string FindNameGlobbing(string packageName, bool includePrerelease, int else { errRecord = new ErrorRecord( - new ArgumentException("-Name with wildcards is only supported for scenarios similar to the following examples: PowerShell*, *ShellGet, *Shell*."), - "FindNameGlobbingFailure", - ErrorCategory.InvalidArgument, + new ArgumentException("-Name with wildcards is only supported for scenarios similar to the following examples: PowerShell*, *ShellGet, *Shell*."), + "FindNameGlobbingFailure", + ErrorCategory.InvalidArgument, this); return string.Empty; @@ -632,9 +632,9 @@ private string FindNameGlobbingWithTag(string packageName, string[] tags, bool i if (names.Length == 0) { errRecord = new ErrorRecord( - new ArgumentException("-Name '*' for NuGet.Server hosted feed repository is not supported"), - "FindNameGlobbingFailure", - ErrorCategory.InvalidArgument, + new ArgumentException("-Name '*' for NuGet.Server hosted feed repository is not supported"), + "FindNameGlobbingFailure", + ErrorCategory.InvalidArgument, this); return string.Empty; @@ -668,9 +668,9 @@ private string FindNameGlobbingWithTag(string packageName, string[] tags, bool i else { errRecord = new ErrorRecord( - new ArgumentException("-Name with wildcards is only supported for scenarios similar to the following examples: PowerShell*, *ShellGet, *Shell*."), - "FindNameGlobbing", - ErrorCategory.InvalidArgument, + new ArgumentException("-Name with wildcards is only supported for scenarios similar to the following examples: PowerShell*, *ShellGet, *Shell*."), + "FindNameGlobbing", + ErrorCategory.InvalidArgument, this); return string.Empty; @@ -780,16 +780,26 @@ private string FindVersionGlobbing(string packageName, VersionRange versionRange /// Name: no wildcard support. /// Examples: Install "PowerShellGet" /// Implementation Note: {repoUri}/Packages(Id='test_local_mod')/Download - /// if prerelease, call into InstallVersion instead. + /// if prerelease, call into InstallVersion instead. /// private Stream InstallName(string packageName, out ErrorRecord errRecord) { _cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::InstallName()"); var requestUrl = $"{Repository.Uri}/Packages/(Id='{packageName}')/Download"; var response = HttpRequestCallForContent(requestUrl, out errRecord); - var responseStream = response.ReadAsStreamAsync().Result; - return responseStream; + if (response is null) + { + errRecord = new ErrorRecord( + new Exception($"No content was returned by repository '{Repository.Name}'"), + "InstallFailureContentNullNuGetServer", + ErrorCategory.InvalidResult, + this); + + return null; + } + + return response.ReadAsStreamAsync().Result; } /// @@ -799,15 +809,25 @@ private Stream InstallName(string packageName, out ErrorRecord errRecord) /// Examples: Install "PowerShellGet" -Version "3.0.0.0" /// Install "PowerShellGet" -Version "3.0.0-beta16" /// API Call: {repoUri}/Packages(Id='Castle.Core',Version='5.1.1')/Download - /// + /// private Stream InstallVersion(string packageName, string version, out ErrorRecord errRecord) { _cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::InstallVersion()"); var requestUrl = $"{Repository.Uri}/Packages(Id='{packageName}',Version='{version}')/Download"; var response = HttpRequestCallForContent(requestUrl, out errRecord); - var responseStream = response.ReadAsStreamAsync().Result; - return responseStream; + if (response is null) + { + errRecord = new ErrorRecord( + new Exception($"No content was returned by repository '{Repository.Name}'"), + "InstallFailureContentNullNuGetServer", + ErrorCategory.InvalidResult, + this); + + return null; + } + + return response.ReadAsStreamAsync().Result; } /// @@ -829,9 +849,9 @@ public int GetCountFromResponse(string httpResponse, out ErrorRecord errRecord) catch (XmlException e) { errRecord = new ErrorRecord( - exception: e, - "GetCountFromResponse", - ErrorCategory.InvalidData, + exception: e, + "GetCountFromResponse", + ErrorCategory.InvalidData, this); } if (errRecord != null) @@ -886,7 +906,7 @@ public static async Task SendRequestForContentAsync(HttpRequestMess { HttpResponseMessage response = await s_client.SendAsync(message); response.EnsureSuccessStatusCode(); - + return response.Content; } catch (HttpRequestException e) diff --git a/src/code/V2ServerAPICalls.cs b/src/code/V2ServerAPICalls.cs index d0a766377..bf2b91305 100644 --- a/src/code/V2ServerAPICalls.cs +++ b/src/code/V2ServerAPICalls.cs @@ -240,9 +240,9 @@ public override FindResults FindTags(string[] tags, bool includePrerelease, Reso if (responses.Count == 0) { errRecord = new ErrorRecord( - new ResourceNotFoundException($"Package with Tags '{String.Join(", ", tags)}' could not be found in repository '{Repository.Name}'."), - "PackageWithSpecifiedTagsNotFound", - ErrorCategory.ObjectNotFound, + new ResourceNotFoundException($"Package with Tags '{String.Join(", ", tags)}' could not be found in repository '{Repository.Name}'."), + "PackageWithSpecifiedTagsNotFound", + ErrorCategory.ObjectNotFound, this); } @@ -294,9 +294,9 @@ public override FindResults FindCommandOrDscResource(string[] tags, bool include { string parameterForErrorMsg = isSearchingForCommands ? "Command" : "DSC Resource"; errRecord = new ErrorRecord( - new ResourceNotFoundException($"Package with {parameterForErrorMsg} '{String.Join(", ", tags)}' could not be found in repository '{Repository.Name}'."), - "PackageWithSpecifiedCmdOrDSCNotFound", - ErrorCategory.InvalidResult, + new ResourceNotFoundException($"Package with {parameterForErrorMsg} '{String.Join(", ", tags)}' could not be found in repository '{Repository.Name}'."), + "PackageWithSpecifiedCmdOrDSCNotFound", + ErrorCategory.InvalidResult, this); } @@ -330,21 +330,21 @@ public override FindResults FindName(string packageName, bool includePrerelease, string response = HttpRequestCall(requestUrlV2, out errRecord); if (errRecord != null) { - return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); + return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); } int count = GetCountFromResponse(response, out errRecord); if (errRecord != null) { - return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); + return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); } if (count == 0) { errRecord = new ErrorRecord( - new ResourceNotFoundException($"Package with name '{packageName}' could not be found in repository '{Repository.Name}'."), - "PackageNotFound", - ErrorCategory.ObjectNotFound, + new ResourceNotFoundException($"Package with name '{packageName}' could not be found in repository '{Repository.Name}'."), + "PackageNotFound", + ErrorCategory.ObjectNotFound, this); response = string.Empty; } @@ -382,21 +382,21 @@ public override FindResults FindNameWithTag(string packageName, string[] tags, b string response = HttpRequestCall(requestUrlV2, out errRecord); if (errRecord != null) { - return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); + return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); } int count = GetCountFromResponse(response, out errRecord); if (errRecord != null) { - return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); + return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); } if (count == 0) { errRecord = new ErrorRecord( new ResourceNotFoundException($"Package with name '{packageName}' and tags '{String.Join(", ", tags)}' could not be found in repository '{Repository.Name}'."), - "PackageNotFound", - ErrorCategory.ObjectNotFound, + "PackageNotFound", + ErrorCategory.ObjectNotFound, this); response = string.Empty; } @@ -436,7 +436,7 @@ public override FindResults FindNameGlobbing(string packageName, bool includePre // If count is 0, early out as this means no packages matching search criteria were found. We want to set the responses array to empty and not set ErrorRecord (as is a globbing scenario). if (initialCount == 0) { - return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); + return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); } int count = (int)Math.Ceiling((double)(initialCount / 100)); @@ -488,7 +488,7 @@ public override FindResults FindNameGlobbingWithTag(string packageName, string[] if (initialCount == 0) { - return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); + return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); } int count = (int)Math.Ceiling((double)(initialCount / 100)); @@ -540,7 +540,7 @@ public override FindResults FindVersionGlobbing(string packageName, VersionRange if (initialCount == 0) { - return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); + return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); } responses.Add(initialResponse); @@ -589,7 +589,7 @@ public override FindResults FindVersion(string packageName, string version, Reso string response = HttpRequestCall(requestUrlV2, out errRecord); if (errRecord != null) { - return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); + return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); } int count = GetCountFromResponse(response, out errRecord); @@ -597,15 +597,15 @@ public override FindResults FindVersion(string packageName, string version, Reso if (errRecord != null) { - return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); + return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); } if (count == 0) { errRecord = new ErrorRecord( - new ResourceNotFoundException($"Package with name '{packageName}', version '{version}' could not be found in repository '{Repository.Name}'."), - "PackageNotFound", - ErrorCategory.ObjectNotFound, + new ResourceNotFoundException($"Package with name '{packageName}', version '{version}' could not be found in repository '{Repository.Name}'."), + "PackageNotFound", + ErrorCategory.ObjectNotFound, this); response = string.Empty; } @@ -638,7 +638,7 @@ public override FindResults FindVersionWithTag(string packageName, string versio string response = HttpRequestCall(requestUrlV2, out errRecord); if (errRecord != null) { - return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); + return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); } int count = GetCountFromResponse(response, out errRecord); @@ -646,19 +646,19 @@ public override FindResults FindVersionWithTag(string packageName, string versio if (errRecord != null) { - return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); + return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); } if (count == 0) { errRecord = new ErrorRecord( - new ResourceNotFoundException($"Package with name '{packageName}', version '{version}' and tags '{String.Join(", ", tags)}' could not be found in repository '{Repository.Name}'."), - "PackageNotFound", - ErrorCategory.ObjectNotFound, + new ResourceNotFoundException($"Package with name '{packageName}', version '{version}' and tags '{String.Join(", ", tags)}' could not be found in repository '{Repository.Name}'."), + "PackageNotFound", + ErrorCategory.ObjectNotFound, this); response = string.Empty; } - + return new FindResults(stringResponse: new string[] { response }, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType); } @@ -704,33 +704,33 @@ private string HttpRequestCall(string requestUrlV2, out ErrorRecord errRecord) catch (ResourceNotFoundException e) { errRecord = new ErrorRecord( - exception: e, - "ResourceNotFound", - ErrorCategory.InvalidResult, + exception: e, + "ResourceNotFound", + ErrorCategory.InvalidResult, this); } catch (UnauthorizedException e) { errRecord = new ErrorRecord( - exception: e, - "UnauthorizedRequest", - ErrorCategory.InvalidResult, + exception: e, + "UnauthorizedRequest", + ErrorCategory.InvalidResult, this); } catch (HttpRequestException e) { errRecord = new ErrorRecord( - exception: e, - "HttpRequestCallFailure", - ErrorCategory.ConnectionError, + exception: e, + "HttpRequestCallFailure", + ErrorCategory.ConnectionError, this); } catch (Exception e) { errRecord = new ErrorRecord( - exception: e, - "HttpRequestCallFailure", - ErrorCategory.ConnectionError, + exception: e, + "HttpRequestCallFailure", + ErrorCategory.ConnectionError, this); } @@ -761,25 +761,25 @@ private HttpContent HttpRequestCallForContent(string requestUrlV2, out ErrorReco catch (HttpRequestException e) { errRecord = new ErrorRecord( - exception: e, - "HttpRequestFailure", - ErrorCategory.ConnectionError, + exception: e, + "HttpRequestFailure", + ErrorCategory.ConnectionError, this); } catch (ArgumentNullException e) { errRecord = new ErrorRecord( - exception: e, - "HttpRequestFailure", - ErrorCategory.InvalidData, + exception: e, + "HttpRequestFailure", + ErrorCategory.InvalidData, this); } catch (InvalidOperationException e) { errRecord = new ErrorRecord( - exception: e, - "HttpRequestFailure", - ErrorCategory.InvalidOperation, + exception: e, + "HttpRequestFailure", + ErrorCategory.InvalidOperation, this); } @@ -787,7 +787,7 @@ private HttpContent HttpRequestCallForContent(string requestUrlV2, out ErrorReco { _cmdletPassedIn.WriteDebug("Response is empty"); } - + return content; } @@ -833,7 +833,7 @@ private string FindTagFromEndpoint(string[] tags, bool includePrerelease, bool i } var requestUrlV2 = $"{Repository.Uri}{typeEndpoint}/Search()?{prereleaseFilter}{typeFilterPart}{tagFilterPart}{paginationParam}"; - + return HttpRequestCall(requestUrlV2: requestUrlV2, out errRecord); } @@ -860,7 +860,7 @@ private string FindCommandOrDscResource(string[] tags, bool includePrerelease, b } var requestUrlV2 = $"{Repository.Uri}/Search()?{prereleaseFilter}&searchTerm='{tagSearchTermPart}'{paginationParam}"; - + return HttpRequestCall(requestUrlV2, out errRecord); } @@ -882,9 +882,9 @@ private string FindNameGlobbing(string packageName, ResourceType type, bool incl if (names.Length == 0) { errRecord = new ErrorRecord( - new ArgumentException("-Name '*' for V2 server protocol repositories is not supported"), - "FindNameGlobbingFailure", - ErrorCategory.InvalidArgument, + new ArgumentException("-Name '*' for V2 server protocol repositories is not supported"), + "FindNameGlobbingFailure", + ErrorCategory.InvalidArgument, this); return string.Empty; @@ -918,9 +918,9 @@ private string FindNameGlobbing(string packageName, ResourceType type, bool incl else { errRecord = new ErrorRecord( - new ArgumentException("-Name with wildcards is only supported for scenarios similar to the following examples: PowerShell*, *ShellGet, *Shell*."), - "FindNameGlobbingFailure", - ErrorCategory.InvalidArgument, + new ArgumentException("-Name with wildcards is only supported for scenarios similar to the following examples: PowerShell*, *ShellGet, *Shell*."), + "FindNameGlobbingFailure", + ErrorCategory.InvalidArgument, this); return string.Empty; @@ -928,7 +928,7 @@ private string FindNameGlobbing(string packageName, ResourceType type, bool incl string typeFilterPart = GetTypeFilterForRequest(type); var requestUrlV2 = $"{Repository.Uri}/Search()?$filter={nameFilter}{typeFilterPart} and {prerelease}{extraParam}"; - + return HttpRequestCall(requestUrlV2, out errRecord); } @@ -950,9 +950,9 @@ private string FindNameGlobbingWithTag(string packageName, string[] tags, Resour if (names.Length == 0) { errRecord = new ErrorRecord( - new ArgumentException("-Name '*' for V2 server protocol repositories is not supported"), - "FindNameGlobbingFailure", - ErrorCategory.InvalidArgument, + new ArgumentException("-Name '*' for V2 server protocol repositories is not supported"), + "FindNameGlobbingFailure", + ErrorCategory.InvalidArgument, this); return string.Empty; @@ -986,9 +986,9 @@ private string FindNameGlobbingWithTag(string packageName, string[] tags, Resour else { errRecord = new ErrorRecord( - new ArgumentException("-Name with wildcards is only supported for scenarios similar to the following examples: PowerShell*, *ShellGet, *Shell*."), - "FindNameGlobbing", - ErrorCategory.InvalidArgument, + new ArgumentException("-Name with wildcards is only supported for scenarios similar to the following examples: PowerShell*, *ShellGet, *Shell*."), + "FindNameGlobbing", + ErrorCategory.InvalidArgument, this); return string.Empty; @@ -1002,7 +1002,7 @@ private string FindNameGlobbingWithTag(string packageName, string[] tags, Resour string typeFilterPart = GetTypeFilterForRequest(type); var requestUrlV2 = $"{Repository.Uri}/Search()?$filter={nameFilter}{tagFilterPart}{typeFilterPart} and {prerelease}{extraParam}"; - + return HttpRequestCall(requestUrlV2, out errRecord); } @@ -1054,7 +1054,7 @@ private string FindVersionGlobbing(string packageName, VersionRange versionRange // because we want to retrieve all the prerelease versions for the upper end of the range // and PSGallery views prerelease as higher than its stable. // eg 3.0.0-prerelease > 3.0.0 - // If looking for versions within '[1.9.9,1.9.9]' including prerelease values, this will change it to search for '[1.9.9,1.9.99]' + // If looking for versions within '[1.9.9,1.9.9]' including prerelease values, this will change it to search for '[1.9.9,1.9.99]' // and find any pkg versions that are 1.9.9-prerelease. string maxString = includePrerelease ? $"{versionRange.MaxVersion.Major}.{versionRange.MaxVersion.Minor}.{versionRange.MaxVersion.Patch.ToString() + "9"}" : $"{versionRange.MaxVersion.ToNormalizedString()}"; @@ -1062,7 +1062,7 @@ private string FindVersionGlobbing(string packageName, VersionRange versionRange { maxPart = String.Format(format, operation, $"'{maxVersion.ToNormalizedString()}'"); } - else { + else { maxPart = String.Format(format, operation, $"'{versionRange.MaxVersion.ToNormalizedString()}'"); } } @@ -1108,7 +1108,7 @@ private string FindVersionGlobbing(string packageName, VersionRange versionRange filterQuery = filterQuery.EndsWith("=") ? string.Empty : filterQuery; var requestUrlV2 = $"{Repository.Uri}/FindPackagesById()?id='{packageName}'&$orderby=NormalizedVersion desc&{paginationParam}{filterQuery}"; - + return HttpRequestCall(requestUrlV2, out errRecord); } @@ -1163,13 +1163,24 @@ private Stream InstallVersion(string packageName, string version, out ErrorRecor } var response = HttpRequestCallForContent(requestUrlV2, out errRecord); - var responseStream = response.ReadAsStreamAsync().Result; + if (errRecord != null) { return new MemoryStream(); } - return responseStream; + if (response is null) + { + errRecord = new ErrorRecord( + new Exception($"No content was returned by repository '{Repository.Name}'"), + "InstallFailureContentNullv2", + ErrorCategory.InvalidResult, + this); + + return null; + } + + return response.ReadAsStreamAsync().Result; } private string GetTypeFilterForRequest(ResourceType type) { @@ -1222,7 +1233,7 @@ public int GetCountFromResponse(string httpResponse, out ErrorRecord errRecord) countSearchSucceeded = int.TryParse(node.InnerText, out count); } } - + if (!countSearchSucceeded) { // Note: not all V2 servers may have the 'count' property implemented or valid (i.e CloudSmith server), in this case try to get 'd:Id' property. @@ -1234,16 +1245,16 @@ public int GetCountFromResponse(string httpResponse, out ErrorRecord errRecord) } else { - _cmdletPassedIn.WriteDebug($"Property 'count' and 'd:Id' could not be found in response. This may indicate that the package could not be found"); + _cmdletPassedIn.WriteDebug($"Property 'count' and 'd:Id' could not be found in response. This may indicate that the package could not be found"); } } } catch (XmlException e) { errRecord = new ErrorRecord( - exception: e, - "GetCountFromResponse", - ErrorCategory.InvalidData, + exception: e, + "GetCountFromResponse", + ErrorCategory.InvalidData, this); } diff --git a/src/code/V3ServerAPICalls.cs b/src/code/V3ServerAPICalls.cs index dec0da5ea..5d5e6687b 100644 --- a/src/code/V3ServerAPICalls.cs +++ b/src/code/V3ServerAPICalls.cs @@ -78,8 +78,8 @@ public override FindResults FindAll(bool includePrerelease, ResourceType type, o _cmdletPassedIn.WriteDebug("In V3ServerAPICalls::FindAll()"); errRecord = new ErrorRecord( new InvalidOperationException($"Find all is not supported for the V3 server protocol repository '{Repository.Name}'"), - "FindAllFailure", - ErrorCategory.InvalidOperation, + "FindAllFailure", + ErrorCategory.InvalidOperation, this); return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v3FindResponseType); @@ -116,9 +116,9 @@ public override FindResults FindCommandOrDscResource(string[] tags, bool include { _cmdletPassedIn.WriteDebug("In V3ServerAPICalls::FindCommandOrDscResource()"); errRecord = new ErrorRecord( - new InvalidOperationException($"Find by CommandName or DSCResource is not supported for the V3 server protocol repository '{Repository.Name}'"), - "FindCommandOrDscResourceFailure", - ErrorCategory.InvalidOperation, + new InvalidOperationException($"Find by CommandName or DSCResource is not supported for the V3 server protocol repository '{Repository.Name}'"), + "FindCommandOrDscResourceFailure", + ErrorCategory.InvalidOperation, this); return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v3FindResponseType); @@ -162,9 +162,9 @@ public override FindResults FindNameGlobbing(string packageName, bool includePre else { errRecord = new ErrorRecord( - new InvalidOperationException($"Find with Name containing wildcards is not supported for the V3 server protocol repository '{Repository.Name}'"), - "FindNameGlobbingFailure", - ErrorCategory.InvalidOperation, + new InvalidOperationException($"Find with Name containing wildcards is not supported for the V3 server protocol repository '{Repository.Name}'"), + "FindNameGlobbingFailure", + ErrorCategory.InvalidOperation, this); return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v3FindResponseType); @@ -185,9 +185,9 @@ public override FindResults FindNameGlobbingWithTag(string packageName, string[] else { errRecord = new ErrorRecord( - new InvalidOperationException($"Find with Name containing wildcards is not supported for the V3 server protocol repository '{Repository.Name}'"), - "FindNameGlobbingWithTagFailure", - ErrorCategory.InvalidOperation, + new InvalidOperationException($"Find with Name containing wildcards is not supported for the V3 server protocol repository '{Repository.Name}'"), + "FindNameGlobbingWithTagFailure", + ErrorCategory.InvalidOperation, this); return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v3FindResponseType); @@ -222,9 +222,9 @@ public override FindResults FindVersionGlobbing(string packageName, VersionRange if (!rootDom.TryGetProperty(versionName, out JsonElement pkgVersionElement)) { errRecord = new ErrorRecord( - new InvalidOrEmptyResponse($"Response does not contain '{versionName}' element."), - "FindVersionGlobbingFailure", - ErrorCategory.InvalidData, + new InvalidOrEmptyResponse($"Response does not contain '{versionName}' element."), + "FindVersionGlobbingFailure", + ErrorCategory.InvalidData, this); return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v3FindResponseType); @@ -243,9 +243,9 @@ public override FindResults FindVersionGlobbing(string packageName, VersionRange catch (Exception e) { errRecord = new ErrorRecord( - exception: e, + exception: e, "FindVersionGlobbingFailure", - ErrorCategory.InvalidResult, + ErrorCategory.InvalidResult, this); return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v3FindResponseType); @@ -322,8 +322,8 @@ private FindResults FindNameGlobbingFromNuGetRepo(string packageName, string[] t { errRecord = new ErrorRecord( new ArgumentException("-Name '*' for V3 server protocol repositories is not supported"), - "FindNameGlobbingFromNuGetRepoFailure", - ErrorCategory.InvalidArgument, + "FindNameGlobbingFromNuGetRepoFailure", + ErrorCategory.InvalidArgument, this); return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v3FindResponseType); @@ -379,9 +379,9 @@ private FindResults FindNameGlobbingFromNuGetRepo(string packageName, string[] t if (!pkgEntry.TryGetProperty(tagsName, out JsonElement tagsItem)) { errRecord = new ErrorRecord( - new JsonParsingException("FindNameGlobbing(): Tags element could not be found in response."), - "GetEntriesFromSearchQueryResourceFailure", - ErrorCategory.InvalidResult, + new JsonParsingException("FindNameGlobbing(): Tags element could not be found in response."), + "GetEntriesFromSearchQueryResourceFailure", + ErrorCategory.InvalidResult, this); return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v3FindResponseType); @@ -410,8 +410,8 @@ private FindResults FindNameGlobbingFromNuGetRepo(string packageName, string[] t { errRecord = new ErrorRecord( exception: e, - "GetEntriesFromSearchQueryResourceFailure", - ErrorCategory.InvalidResult, + "GetEntriesFromSearchQueryResourceFailure", + ErrorCategory.InvalidResult, this); break; @@ -439,9 +439,9 @@ private FindResults FindTagsFromNuGetRepo(string[] tags, bool includePrerelease, if (tagPkgEntries.Count == 0) { errRecord = new ErrorRecord( - new ResourceNotFoundException($"Package with Tags '{String.Join(", ", tags)}' could not be found in repository '{Repository.Name}'."), - "PackageWithSpecifiedTagsNotFound", - ErrorCategory.ObjectNotFound, + new ResourceNotFoundException($"Package with Tags '{String.Join(", ", tags)}' could not be found in repository '{Repository.Name}'."), + "PackageWithSpecifiedTagsNotFound", + ErrorCategory.ObjectNotFound, this); return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v3FindResponseType); @@ -480,9 +480,9 @@ private FindResults FindNameHelper(string packageName, string[] tags, bool inclu if (!rootDom.TryGetProperty(versionName, out JsonElement pkgVersionElement)) { errRecord = new ErrorRecord( - new InvalidOrEmptyResponse($"Response does not contain '{versionName}' element for search with Name '{packageName}' in '{Repository.Name}'."), - "FindNameFailure", - ErrorCategory.InvalidResult, + new InvalidOrEmptyResponse($"Response does not contain '{versionName}' element for search with Name '{packageName}' in '{Repository.Name}'."), + "FindNameFailure", + ErrorCategory.InvalidResult, this); return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v3FindResponseType); @@ -490,9 +490,9 @@ private FindResults FindNameHelper(string packageName, string[] tags, bool inclu if (!rootDom.TryGetProperty(tagsName, out JsonElement tagsItem)) { errRecord = new ErrorRecord( - new InvalidOrEmptyResponse($"Response does not contain '{tagsName}' element for search with Name '{packageName}' in '{Repository.Name}'."), - "FindNameFailure", - ErrorCategory.InvalidResult, + new InvalidOrEmptyResponse($"Response does not contain '{tagsName}' element for search with Name '{packageName}' in '{Repository.Name}'."), + "FindNameFailure", + ErrorCategory.InvalidResult, this); return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v3FindResponseType); @@ -515,9 +515,9 @@ private FindResults FindNameHelper(string packageName, string[] tags, bool inclu catch (Exception e) { errRecord = new ErrorRecord( - exception: e, - "FindNameFailure", - ErrorCategory.InvalidResult, + exception: e, + "FindNameFailure", + ErrorCategory.InvalidResult, this); return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v3FindResponseType); @@ -527,9 +527,9 @@ private FindResults FindNameHelper(string packageName, string[] tags, bool inclu if (String.IsNullOrEmpty(latestVersionResponse)) { errRecord = new ErrorRecord( - new ResourceNotFoundException($"Package with name '{packageName}' could not be found in repository '{Repository.Name}'."), - "PackageNotFound", - ErrorCategory.ObjectNotFound, + new ResourceNotFoundException($"Package with name '{packageName}' could not be found in repository '{Repository.Name}'."), + "PackageNotFound", + ErrorCategory.ObjectNotFound, this); return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v3FindResponseType); @@ -541,9 +541,9 @@ private FindResults FindNameHelper(string packageName, string[] tags, bool inclu if (errRecord == null) { errRecord = new ErrorRecord( - new ResourceNotFoundException($"Package with name '{packageName}' and tags '{String.Join(", ", tags)}' could not be found in repository '{Repository.Name}'."), - "PackageNotFound", - ErrorCategory.ObjectNotFound, + new ResourceNotFoundException($"Package with name '{packageName}' and tags '{String.Join(", ", tags)}' could not be found in repository '{Repository.Name}'."), + "PackageNotFound", + ErrorCategory.ObjectNotFound, this); } @@ -562,9 +562,9 @@ private FindResults FindVersionHelper(string packageName, string version, string if (!NuGetVersion.TryParse(version, out NuGetVersion requiredVersion)) { errRecord = new ErrorRecord( - new ArgumentException($"Version {version} to be found is not a valid NuGet version."), - "FindNameFailure", - ErrorCategory.InvalidArgument, + new ArgumentException($"Version {version} to be found is not a valid NuGet version."), + "FindNameFailure", + ErrorCategory.InvalidArgument, this); return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v3FindResponseType); @@ -590,9 +590,9 @@ private FindResults FindVersionHelper(string packageName, string version, string if (!rootDom.TryGetProperty(versionName, out JsonElement pkgVersionElement)) { errRecord = new ErrorRecord( - new InvalidOrEmptyResponse($"Response does not contain '{versionName}' element for search with name '{packageName}' and version '{version}' in repository '{Repository.Name}'."), - "FindVersionFailure", - ErrorCategory.InvalidResult, + new InvalidOrEmptyResponse($"Response does not contain '{versionName}' element for search with name '{packageName}' and version '{version}' in repository '{Repository.Name}'."), + "FindVersionFailure", + ErrorCategory.InvalidResult, this); return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v3FindResponseType); @@ -600,9 +600,9 @@ private FindResults FindVersionHelper(string packageName, string version, string if (!rootDom.TryGetProperty(tagsName, out JsonElement tagsItem)) { errRecord = new ErrorRecord( - new InvalidOrEmptyResponse($"Response does not contain '{tagsName}' element for search with name '{packageName}' and version '{version}' in repository '{Repository.Name}'."), - "FindVersionFailure", - ErrorCategory.InvalidResult, + new InvalidOrEmptyResponse($"Response does not contain '{tagsName}' element for search with name '{packageName}' and version '{version}' in repository '{Repository.Name}'."), + "FindVersionFailure", + ErrorCategory.InvalidResult, this); return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v3FindResponseType); @@ -622,9 +622,9 @@ private FindResults FindVersionHelper(string packageName, string version, string catch (Exception e) { errRecord = new ErrorRecord( - exception: e, - "FindVersionFailure", - ErrorCategory.InvalidResult, + exception: e, + "FindVersionFailure", + ErrorCategory.InvalidResult, this); return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v3FindResponseType); @@ -634,9 +634,9 @@ private FindResults FindVersionHelper(string packageName, string version, string if (String.IsNullOrEmpty(latestVersionResponse)) { errRecord = new ErrorRecord( - new ResourceNotFoundException($"Package with name '{packageName}', version '{version}' could not be found in repository '{Repository.Name}'."), - "PackageNotFound", - ErrorCategory.ObjectNotFound, + new ResourceNotFoundException($"Package with name '{packageName}', version '{version}' could not be found in repository '{Repository.Name}'."), + "PackageNotFound", + ErrorCategory.ObjectNotFound, this); return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v3FindResponseType); @@ -647,9 +647,9 @@ private FindResults FindVersionHelper(string packageName, string version, string if (errRecord == null) { errRecord = new ErrorRecord( - new ResourceNotFoundException($"FindVersion(): Package with name '{packageName}', version '{version}' and tags '{String.Join(", ", tags)}' could not be found in repository '{Repository.Name}'."), - "PackageNotFound", - ErrorCategory.ObjectNotFound, + new ResourceNotFoundException($"FindVersion(): Package with name '{packageName}', version '{version}' and tags '{String.Join(", ", tags)}' could not be found in repository '{Repository.Name}'."), + "PackageNotFound", + ErrorCategory.ObjectNotFound, this); } @@ -717,9 +717,9 @@ private Stream InstallHelper(string packageName, NuGetVersion version, out Error if (versionedResponses.Length == 0) { errRecord = new ErrorRecord( - new Exception($"Package with name '{packageName}' and version '{version}' could not be found in repository '{Repository.Name}'"), - "InstallFailure", - ErrorCategory.InvalidResult, + new Exception($"Package with name '{packageName}' and version '{version}' could not be found in repository '{Repository.Name}'"), + "InstallFailure", + ErrorCategory.InvalidResult, this); return null; @@ -748,9 +748,9 @@ private Stream InstallHelper(string packageName, NuGetVersion version, out Error if (String.IsNullOrEmpty(pkgContentUrl)) { errRecord = new ErrorRecord( - new Exception($"Package with name '{packageName}' and version '{version}' could not be found in repository '{Repository.Name}'"), - "InstallFailure", - ErrorCategory.InvalidResult, + new Exception($"Package with name '{packageName}' and version '{version}' could not be found in repository '{Repository.Name}'"), + "InstallFailure", + ErrorCategory.InvalidResult, this); return null; @@ -762,9 +762,18 @@ private Stream InstallHelper(string packageName, NuGetVersion version, out Error return null; } - pkgStream = content.ReadAsStreamAsync().Result; + if (content is null) + { + errRecord = new ErrorRecord( + new Exception($"No content was returned by repository '{Repository.Name}'"), + "InstallFailureContentNullv3", + ErrorCategory.InvalidResult, + this); - return pkgStream; + return null; + } + + return content.ReadAsStreamAsync().Result; } /// @@ -860,8 +869,8 @@ private Dictionary GetResourcesFromServiceIndex(out ErrorRecord if (!resource.TryGetProperty("@type", out JsonElement typeElement)) { errRecord = new ErrorRecord( - new JsonParsingException($"@type element not found for resource in service index for repository '{Repository.Name}'"), "GetResourcesFromServiceIndexFailure", - ErrorCategory.InvalidResult, + new JsonParsingException($"@type element not found for resource in service index for repository '{Repository.Name}'"), "GetResourcesFromServiceIndexFailure", + ErrorCategory.InvalidResult, this); return new Dictionary(); @@ -870,9 +879,9 @@ private Dictionary GetResourcesFromServiceIndex(out ErrorRecord if (!resource.TryGetProperty("@id", out JsonElement idElement)) { errRecord = new ErrorRecord( - new JsonParsingException($"@id element not found for resource in service index for repository '{Repository.Name}'"), - "GetResourcesFromServiceIndexFailure", - ErrorCategory.InvalidResult, + new JsonParsingException($"@id element not found for resource in service index for repository '{Repository.Name}'"), + "GetResourcesFromServiceIndexFailure", + ErrorCategory.InvalidResult, this); return new Dictionary(); @@ -887,9 +896,9 @@ private Dictionary GetResourcesFromServiceIndex(out ErrorRecord catch (Exception e) { errRecord = new ErrorRecord( - new Exception($"Exception parsing service index JSON for respository '{Repository.Name}' with error: {e.Message}"), - "GetResourcesFromServiceIndexFailure", - ErrorCategory.InvalidResult, + new Exception($"Exception parsing service index JSON for respository '{Repository.Name}' with error: {e.Message}"), + "GetResourcesFromServiceIndexFailure", + ErrorCategory.InvalidResult, this); return new Dictionary(); @@ -941,9 +950,9 @@ private string FindRegistrationsBaseUrl(Dictionary resources, ou else { errRecord = new ErrorRecord( - new ResourceNotFoundException($"RegistrationBaseUrl resource could not be found for repository '{Repository.Name}'"), - "FindRegistrationsBaseUrlFailure", - ErrorCategory.InvalidResult, + new ResourceNotFoundException($"RegistrationBaseUrl resource could not be found for repository '{Repository.Name}'"), + "FindRegistrationsBaseUrlFailure", + ErrorCategory.InvalidResult, this); } @@ -979,9 +988,9 @@ private string FindSearchQueryService(Dictionary resources, out else { errRecord = new ErrorRecord( - new ResourceNotFoundException($"SearchQueryService resource could not be found for Repository '{Repository.Name}'"), - "FindSearchQueryServiceFailure", - ErrorCategory.InvalidResult, + new ResourceNotFoundException($"SearchQueryService resource could not be found for Repository '{Repository.Name}'"), + "FindSearchQueryServiceFailure", + ErrorCategory.InvalidResult, this); } @@ -1005,9 +1014,9 @@ private JsonElement[] GetMetadataElementFromIdLinkElement(JsonElement idLinkElem { if (errRecord.Exception is ResourceNotFoundException) { errRecord = new ErrorRecord( - new ResourceNotFoundException($"Package with name '{packageName}' could not be found in repository '{Repository.Name}'.", errRecord.Exception), - "PackageNotFound", - ErrorCategory.ObjectNotFound, + new ResourceNotFoundException($"Package with name '{packageName}' could not be found in repository '{Repository.Name}'.", errRecord.Exception), + "PackageNotFound", + ErrorCategory.ObjectNotFound, this); } @@ -1022,9 +1031,9 @@ private JsonElement[] GetMetadataElementFromIdLinkElement(JsonElement idLinkElem if (!rootDom.TryGetProperty(itemsName, out JsonElement innerItemsElement)) { errRecord = new ErrorRecord( - new ResourceNotFoundException($"'{itemsName}' element for package with name '{packageName}' could not be found in JFrog repository '{Repository.Name}'"), - "GetElementForJFrogRepoFailure", - ErrorCategory.InvalidResult, + new ResourceNotFoundException($"'{itemsName}' element for package with name '{packageName}' could not be found in JFrog repository '{Repository.Name}'"), + "GetElementForJFrogRepoFailure", + ErrorCategory.InvalidResult, this); return innerItems; @@ -1049,9 +1058,9 @@ private JsonElement[] GetMetadataElementFromIdLinkElement(JsonElement idLinkElem catch (Exception e) { errRecord = new ErrorRecord( - exception: e, - "MetadataElementForIdElementRetrievalFailure", - ErrorCategory.InvalidResult, + exception: e, + "MetadataElementForIdElementRetrievalFailure", + ErrorCategory.InvalidResult, this); } @@ -1216,7 +1225,7 @@ private string[] GetMetadataElementsFromResponse(string response, string propert return versionedPkgResponses.ToArray(); } - + /// /// Helper method iterates through the entries in the registrationsUrl for a specific package and all its versions. /// This contains an inner items element (containing the package metadata) and the packageContent element (containing URI through which the .nupkg can be downloaded) @@ -1237,9 +1246,9 @@ private string[] GetVersionedResponsesFromRegistrationsResource(string registrat if (errRecord.Exception is ResourceNotFoundException) { errRecord = new ErrorRecord( - new ResourceNotFoundException($"Package with name '{packageName}' could not be found in repository '{Repository.Name}'.", errRecord.Exception), - "PackageNotFound", - ErrorCategory.ObjectNotFound, + new ResourceNotFoundException($"Package with name '{packageName}' could not be found in repository '{Repository.Name}'.", errRecord.Exception), + "PackageNotFound", + ErrorCategory.ObjectNotFound, this); } @@ -1315,7 +1324,7 @@ private bool IsLatestVersionFirstForSearch(string[] versionedResponses, out Erro return latestVersionFirst; } - + string firstVersion = firstVersionElement.ToString(); if (!NuGetVersion.TryParse(firstVersion, out firstPkgVersion)) @@ -1343,7 +1352,7 @@ private bool IsLatestVersionFirstForSearch(string[] versionedResponses, out Erro return latestVersionFirst; } - + string lastVersion = lastVersionElement.ToString(); if (!NuGetVersion.TryParse(lastVersion, out lastPkgVersion)) @@ -1366,9 +1375,9 @@ private bool IsLatestVersionFirstForSearch(string[] versionedResponses, out Erro catch (Exception e) { errRecord = new ErrorRecord( - exception: e, - "LatestVersionFirstSearchFailure", - ErrorCategory.InvalidResult, + exception: e, + "LatestVersionFirstSearchFailure", + ErrorCategory.InvalidResult, this); return true; @@ -1435,11 +1444,11 @@ private bool IsRequiredTagSatisfied(JsonElement tagsElement, string[] tags, out catch (Exception e) { errRecord = new ErrorRecord( - exception: e, - "GetResponsesFromRegistrationsResourceFailure", - ErrorCategory.InvalidResult, + exception: e, + "GetResponsesFromRegistrationsResourceFailure", + ErrorCategory.InvalidResult, this); - + return false; } @@ -1498,17 +1507,17 @@ private JsonElement[] GetJsonElementArr(string request, string propertyName, out { // scenario where the feed is not active anymore, i.e confirmed for JFrogArtifactory. The default error message is not intuitive. errRecord = new ErrorRecord( - exception: new Exception($"JSON response from repository {Repository.Name} could not be parsed, likely due to the feed being inactive or invalid, with inner exception: {e.Message}"), + exception: new Exception($"JSON response from repository {Repository.Name} could not be parsed, likely due to the feed being inactive or invalid, with inner exception: {e.Message}"), "FindVersionGlobbingFailure", - ErrorCategory.InvalidResult, + ErrorCategory.InvalidResult, this); } catch (Exception e) { errRecord = new ErrorRecord( - exception: e, - "GetResponsesFromRegistrationsResourceFailure", - ErrorCategory.InvalidResult, + exception: e, + "GetResponsesFromRegistrationsResourceFailure", + ErrorCategory.InvalidResult, this); } @@ -1534,33 +1543,33 @@ private string HttpRequestCall(string requestUrlV3, out ErrorRecord errRecord) catch (ResourceNotFoundException e) { errRecord = new ErrorRecord( - exception: e, - "ResourceNotFound", - ErrorCategory.InvalidResult, + exception: e, + "ResourceNotFound", + ErrorCategory.InvalidResult, this); } catch (UnauthorizedException e) { errRecord = new ErrorRecord( - exception: e, - "UnauthorizedRequest", - ErrorCategory.InvalidResult, + exception: e, + "UnauthorizedRequest", + ErrorCategory.InvalidResult, this); } catch (HttpRequestException e) { errRecord = new ErrorRecord( - exception: e, - "HttpRequestCallFailure", - ErrorCategory.InvalidResult, + exception: e, + "HttpRequestCallFailure", + ErrorCategory.InvalidResult, this); } catch (Exception e) { errRecord = new ErrorRecord( - exception: e, - "HttpRequestCallFailure", - ErrorCategory.InvalidResult, + exception: e, + "HttpRequestCallFailure", + ErrorCategory.InvalidResult, this); } @@ -1585,9 +1594,9 @@ private HttpContent HttpRequestCallForContent(string requestUrlV3, out ErrorReco catch (Exception e) { errRecord = new ErrorRecord( - exception: e, - "HttpRequestCallForContentFailure", - ErrorCategory.InvalidResult, + exception: e, + "HttpRequestCallForContentFailure", + ErrorCategory.InvalidResult, this); }