Skip to content

Improve Error Handling for RFC 7807 Compatibility — Add ProcessResponseAsync #102

@saampaark

Description

@saampaark

Currently, when consuming APIs that follow RFC 7807 (Problem Details for HTTP APIs), the autogenerated client does not expose response.Content in ApiException, making it difficult to access the actual error body content when an error (e.g., 400 Bad Request) is returned.

Structured error details should be returned in the body using application/problem+json, which requires access to response.Content. However, since the client does not expose this directly, we are forced to intercept it by implementing a partial method like this:

public partial class MyClient 
{
    partial void ProcessResponse(
        HttpClient client,
        HttpResponseMessage response)
    {
        if (!response.IsSuccessStatusCode)
        {
            // Extract problem details into ReasonPhrase (as workaround)
            response.ReasonPhrase = response.Content.ReadAsStringAsync().Result;
        }
    }
}

Consider adding support for:

  • ProcessResponseAsync (in addition to the sync ProcessResponse) in order to avoid calling .Result which blocks the thread and is an antipattern.
  • Easier access to the response content.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions