Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to retrieving an asset that does not exist throws exception rather than returning null. #251

Open
mattnield opened this issue Sep 5, 2023 · 0 comments

Comments

@mattnield
Copy link

Brief bug description

When trying to retrieve an AssetModel (and other items such as LanguageVariantModel), code examples show that a nullable object can be returned ( see Retrieve an asset ). The assumption here is that if no item is found, then a null item is returned according to the code in the C# sample:

// Tip: Find more about .NET SDKs at https://kontent.ai/learn/net
using Kontent.Ai.Management;

var client = new ManagementClient(new ManagementOptions
{
    ApiKey = "<YOUR_API_KEY>",
    ProjectId = "<YOUR_PROJECT_ID>"
});

var identifier = Reference.ById(Guid.Parse("fcbb12e6-66a3-4672-85d9-d502d16b8d9c"));
// var identifier = Reference.ByCodename("which-brewing-fits-you");

var response = await client.GetAssetAsync(identifier);

Assert.NotNull(response);

What actually happens is that a ManagementException is thrown:

Unhandled exception. Kontent.Ai.Management.Exceptions.ManagementException: The requested asset '{external id: 035166}' was not found.
   at Kontent.Ai.Management.Modules.HttpClient.ManagementHttpClient.SendAsync(IMessageCreator messageCreator, String endpointUrl, HttpMethod method, HttpContent requestContent, Dictionary`2 headers)
   at Kontent.Ai.Management.Modules.ActionInvoker.ActionInvoker.InvokeReadOnlyMethodAsync[TResponse](String endpointUrl, HttpMethod method, Dictionary`2 headers)
   at Kontent.Ai.Management.ManagementClient.GetAssetAsync(Reference identifier)

Is this intended functionality and does the documentation just need to be updated? It's a frustrating pattern, as integration and content migration needs to have an unusually high number of try-catch block to deal with determining if an item exists.

Test environment

  • Platform/OS: .NET 6, macOS Ventura 31.5.1
  • Version: Kontent.ai.Management 4.6.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant