-
Notifications
You must be signed in to change notification settings - Fork 13
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
Can not check if store exists #374
Comments
@jenschude would you be able to assist? |
The API answers with a 404 which results in the NotFoundException. In the Java SDK we added a NotFoundExceptionMiddleware which returns null in case of an NotFoundException. You may be able to register an additional MessageHandler to the client like this: s.UseCommercetoolsApi(...)
.AddHttpMessageHandler(new NotFoundExceptionHandler());
.AddHttpMessageHandler(c => new NotFoundExceptionHandler(c.GetService<MyHelperService>())); // with addtionional DependencyInjection I didn't tried it yet if the handler is being called before or after the ErrorHandler. Another option would be to add a new Middleware but atm the SDK is not as extendable as the Java SDK regarding middlewares. |
Ok. seems like a workaround worth trying, but this should really be fixed in the sdk. I can also push a PR with that exact change if you want, but idk if this repo is open to contributions, let me know what you think. |
@jenschude hello could you give any guidance regarding my last message? would you accept a PR or would i need a support ticket? |
The repository is open to contributors. So you are free to open a PR. |
Took a quick look, I could not get the tests to run locally; System.AggregateException
One or more errors occurred. (Value cannot be null. (Parameter 'instance')) (The following constructor parameters did not have matching fixture data: ServiceProviderFixture serviceProviderFixture)
Exception doesn't have a stacktrace
System.ArgumentNullException
Value cannot be null. (Parameter 'instance')
at System.ComponentModel.DataAnnotations.ValidationContext..ctor(Object instance, IServiceProvider serviceProvider, IDictionary`2 items)
at System.ComponentModel.DataAnnotations.ValidationContext..ctor(Object instance)
at commercetools.Sdk.HttpApi.DependencyInjectionSetup.UseSingleClient(IServiceCollection services, IConfiguration configuration, String clientName, TokenFlow tokenFlow)
at commercetools.Sdk.HttpApi.DependencyInjectionSetup.UseHttpApi(IServiceCollection services, IConfiguration configuration, IDictionary`2 clients)
at Microsoft.Extensions.DependencyInjection.DependencyInjectionSetup.UseCommercetools(IServiceCollection services, IConfiguration configuration, IDictionary`2 clients, SerializationConfiguration serializationConfiguration)
at Microsoft.Extensions.DependencyInjection.DependencyInjectionSetup.UseCommercetools(IServiceCollection services, IConfiguration configuration, String clientName, TokenFlow tokenFlow, SerializationConfiguration serializationConfiguration)
at commercetools.Sdk.BCTest.ServiceProviderFixture..ctor(IMessageSink diagnosticMessageSink) in C:\repos\commercetools-dotnet-core-sdk-v2\commercetools.Sdk\compat\commercetools.Sdk.BCTest\ServiceProviderFixture.cs:line 36
Xunit.Sdk.TestClassException
The following constructor parameters did not have matching fixture data: ServiceProviderFixture serviceProviderFixture
Exception doesn't have a stacktrace |
You will have to add an appsettings file to the test project appsettings.test.Development.json
or set up these environment variables:
|
Oh just saw that the error is coming from the BCTest project. Yes this is atm not tested. :) |
hiya from the docs:
https://docs.commercetools.com/api/projects/stores#check-if-store-exists
You can make HEAD calls and see if a resource exists or not.
Great - but the sdk automatically faults on a not found error;
Always faults.
I think that in the
ErrorHandler
we should check the http method and not throw on notfound errors when doing /head calls or something or make it configurable.Otherwise please advise how i would check if a resource exists (without a try-catch).
To be clear; exceptions are to be used in exceptional cases, and a exists or not case is normal operation, not exceptional. Such actions should not throw.
The text was updated successfully, but these errors were encountered: