Skip to content

Commit

Permalink
wrap error returned for ADO package not found
Browse files Browse the repository at this point in the history
  • Loading branch information
anamnavi committed Oct 14, 2024
1 parent c9746cf commit c0177b8
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/code/V2ServerAPICalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,17 @@ public override FindResults FindName(string packageName, bool includePrerelease,
string response = HttpRequestCall(requestUrlV2, out errRecord);
if (errRecord != null)
{
// usually this is for errors in calling the V2 server, but for ADO V2 this error will include package not found errors which we want to deliver in a standard message
if (_isADORepo && errRecord.Exception is ResourceNotFoundException)
{
errRecord = new ErrorRecord(
new ResourceNotFoundException($"Package with name '{packageName}' could not be found in repository '{Repository.Name}'. For ADO feed, if the package is in an upstream feed make sure you are authenticated to the upstream feed.", errRecord.Exception),
"PackageNotFound",
ErrorCategory.ObjectNotFound,
this);
response = string.Empty;
}

return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType);
}

Expand Down Expand Up @@ -648,6 +659,17 @@ public override FindResults FindVersion(string packageName, string version, Reso
string response = HttpRequestCall(requestUrlV2, out errRecord);
if (errRecord != null)
{
// usually this is for errors in calling the V2 server, but for ADO V2 this error will include package not found errors which we want to deliver with a standard message
if (_isADORepo && errRecord.Exception is ResourceNotFoundException)
{
errRecord = new ErrorRecord(
new ResourceNotFoundException($"Package with name '{packageName}' and version '{version}' could not be found in repository '{Repository.Name}'. For ADO feed, if the package is in an upstream feed make sure you are authenticated to the upstream feed.", errRecord.Exception),
"PackageNotFound",
ErrorCategory.ObjectNotFound,
this);
response = string.Empty;
}

return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType);
}

Expand Down

0 comments on commit c0177b8

Please sign in to comment.