Skip to content

Conversation

koen-lee
Copy link

@koen-lee koen-lee commented Sep 25, 2025

See also #4349; this PR aims to change the developer experience from

ApiSdk.Models.ProblemDetails:Exception of type 'ApiSdk.Models.ProblemDetails' was thrown.
         at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.ThrowIfFailedResponse....

to

ApiSdk.Models.ProblemDetails:403 Client certificate does not have required 'Write' role
         at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.ThrowIfFailedResponse...

in case the OpenAPI document provides a description per status code.
The current behavior requires an extension for pretty error messages.

Before putting some tools to work to implement this for other languages, first I'd like to check whether this feature design fits the project.

It adds a constructor with a message to error classes and adds the description from the document to the error map:

            var errorMapping = new Dictionary<string, ParsableFactory<IParsable>>
            {
                { "400", (parseNode) => global::ApiSdk.Models.ValidationProblemDetails.CreateFromDiscriminatorValueWithMessage(parseNode, "400 Invalid hash format or hash mismatch") },
                { "401", (parseNode) => global::ApiSdk.Models.ProblemDetails.CreateFromDiscriminatorValueWithMessage(parseNode, "401 Missing or invalid client certificate") },
                { "403", (parseNode) => global::ApiSdk.Models.ProblemDetails.CreateFromDiscriminatorValueWithMessage(parseNode, "403 Client certificate does not have required 'Write' role") },
                { "409", (parseNode) => global::ApiSdk.Models.ProblemDetails.CreateFromDiscriminatorValueWithMessage(parseNode, "409 Upload for this hash already in progress, please retry") },
            };

The existing extension message logic is still intact, so this is used as fallback only.

@koen-lee koen-lee requested a review from a team as a code owner September 25, 2025 12:07
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

Successfully merging this pull request may close these issues.

1 participant