Git Product home page Git Product logo

Comments (3)

jenschude avatar jenschude commented on June 8, 2024

Also i didn't completely understood your problem. I try to give some insights to the SDK client.

The client utilizes a middleware approach. E.g. the Authorization is injected by an AuthorizationMiddleware. This middleware just adds he AuthHeader to the request. The TokenProvider which seems to be in your case the AnonymToken has to return a Token and/or refresh it in case it's expired.

The DependencyInjectionSetup class sets up a HttpClient instance with some DelegatingMessageHandlers which will be instantiated in the ClientFactory. There you will find this line:

.AddHttpMessageHandler(c => new ErrorHandler(message => serializerFactory(c).Deserialize(errorResponseTypeMapper(message), message.ExtractResponseBody())))

The ErrorHandler will convert all responses with a StatusCode greater or equals 400 to an Exception. This should be what you are asking for in case you wanna use a custom configured HttpClient.

from commercetools-dotnet-core-sdk-v2.

codewode avatar codewode commented on June 8, 2024

Thanks @jenschude for your reply. I must admit that I am not a C# expert. I must be doing something differently. Here is my situation and I believe I must be doing something wrong, so I have created a sample project in-case you would like to try that out.

https://github.com/codewode/commercetools-anonym-token

what am I trying to achieve is, everytime a customer requests to create a cart, then it will generate token, that token will be used in the subsequent requests to update/get the cart. I expect that, if the given token is expired/invalid, then it will throw 401 exception, however I am always getting an empty cart with 200 OK Response. I have also attached postman collection.

from commercetools-dotnet-core-sdk-v2.

codewode avatar codewode commented on June 8, 2024

I certainly missed the point from the docs, after adding SetupClient, it got fixed.

          services.SetupClient(
                "MeClient",
                errorTypeMapper => typeof(ErrorResponse),
                s => s.GetService<SerializerService>()
            );

from commercetools-dotnet-core-sdk-v2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.