Skip to content

[Docs]: Make v12 migration for response.Error.Content (Error -> ApiExceptionBase) discoverable #2189

Description

@glennawatson

Summary

Users upgrading to v12 report they can no longer find response.Error.Content on an IApiResponse<T>. The data is still there — but the access pattern changed in the v11/v12 exception refactor and the migration path, while technically documented, is not discoverable enough. This issue tracks improving the docs/upgrade notes (this is not a code defect).

Reported in discussion #2187.

What actually changed

  • IApiResponse<T>.Error was widened from ApiException? to ApiExceptionBase? (src/Refit/ApiResponse{T}.cs:121), the shared base of ApiException (server responded) and ApiRequestException (transport failure).
  • The response body Content still lives on the derived ApiException (src/Refit/ApiException.cs:162); ApiExceptionBase only exposes RequestContent.
  • Net effect: response.Error.Content no longer compiles, so users assume the feature was removed. It wasn't — it just needs a narrowing step.

Correct usage in v12

// Preferred: safe narrowing to the response-side exception
if (response.HasResponseError(out var apiException))
{
    _logger.LogError(apiException, apiException.Content);
}

// Or a direct cast / pattern match
var content = (response.Error as ApiException)?.Content;

Why it's hard to find

  • The README breaking-changes section (lines ~187–191) explains the Error type change and points at HasResponseError(...), and there's a worked example (lines ~2068–2071) using responseError.Content — but neither is keyed off the symptom users actually hit ("Error.Content doesn't exist anymore").
  • Nothing connects the old Error.Content expression to the new HasResponseError/cast pattern, so a Ctrl-F for "Content" doesn't lead a migrating user to the fix.

Proposed documentation changes

  1. Add an explicit before/after migration snippet in the v12 upgrade notes:
    • Before: var body = response.Error.Content;
    • After: response.HasResponseError(out var e)e.Content (and mention the (Error as ApiException)?.Content shorthand).
  2. Cross-reference this from the exception-handling section so searching for "Error.Content" or "Content" lands on the migration note.
  3. Optional: a short FAQ/troubleshooting entry ("response.Error.Content no longer compiles after upgrading to v12") pointing at HasResponseError.

Out of scope

No runtime/API change. If a future ergonomic helper is desired (e.g. a convenience accessor for response content on IApiResponse), that should be a separate enhancement proposal, not part of this docs fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions