{"record":{"id":"667f6af19e692ebc","repo":"reactiveui/refit","slug":"the-response-is-unavailable-for-this-api-response","errorCode":null,"errorMessage":"The response is unavailable for this API response.","messagePattern":"The response is unavailable for this API response\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Refit/ApiResponse{T}.cs","lineNumber":209,"sourceCode":"        {\n            return;\n        }\n\n        response?.Dispose();\n    }\n\n    /// <summary>Throws the appropriate API exception for an unsuccessful response.</summary>\n    /// <returns>A task that represents the asynchronous validation operation.</returns>\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    internal ValueTask<ApiResponse<T>> EnsureSlowAsync() => ThrowsApiExceptionAsync();\n\n    /// <summary>Throws the appropriate API exception for an unsuccessful response.</summary>\n    /// <returns>A task that represents the asynchronous throw operation.</returns>\n    /// <exception cref=\"InvalidOperationException\">No HTTP response was ever received, so there is nothing to build an API exception from.</exception>\n    internal async ValueTask<ApiResponse<T>> ThrowsApiExceptionAsync()\n    {\n        var responseMessage = response\n                              ?? throw new InvalidOperationException(\n                                  \"The response is unavailable for this API response.\");\n\n        var exception =\n            Error\n            ?? await ApiException\n                .Create(\n                    request,\n                    request.Method,\n                    responseMessage,\n                    Settings)\n                .ConfigureAwait(false);\n\n        Dispose();\n\n        throw exception;\n    }\n}\n","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/reactiveui/refit/blob/b455f65ecc4c97d092317e349cb775f9cfc6bcdf/src/Refit/ApiResponse{T}.cs#L191-L227","documentation":"Thrown by ApiResponse<T>.ThrowsApiExceptionAsync when the response field is null — meaning no HTTP response was ever received (the call failed before getting a response, e.g. cancellation, DNS failure, or transport exception). There is no response to build an ApiException from, so the operation is invalid in that state.","triggerScenarios":"Calling EnsureSuccessStatusCode/EnsureSlowAsync on an ApiResponse<T> whose underlying response is null, which occurs when the pipeline captured an error (like an OperationCanceledException or HttpRequestException) without ever materializing an HttpResponseMessage. Typically reached when error-handling code assumes a response always exists.","commonSituations":"Cancellation (CancellationToken triggered) aborting the call before a response; transport-layer failures (DNS, connection refused, timeout) that never yield a response; wrapping ApiResponse and unconditionally calling the ensure method.","solutions":["Check ApiResponse.Error / whether a response exists before forcing an ApiException; if Error is already set you may not need ThrowsApiExceptionAsync.","Handle the transport/cancellation error separately (catch OperationCanceledException/HttpRequestException) rather than routing it through the ApiException path.","For cancellation, verify the token before/around the call and treat a missing response as a non-HTTP failure."],"exampleFix":"// before\nvar resp = await client.GetAsync(id);\nawait resp.EnsureSuccessAsync(); // throws if no response was received\n\n// after — distinguish transport failure from HTTP error\nif (resp.Error is OperationCanceledException) throw resp.Error;\nif (!resp.IsSuccessStatusCode) await resp.EnsureSuccessAsync();","handlingStrategy":"try-catch","validationCode":"// Distinguish 'no response' (transport/cancel) from 'got an error response'.\nif (apiResponse.Error is OperationCanceledException or HttpRequestException)\n    throw apiResponse.Error;\nif (!apiResponse.IsSuccessStatusCode)\n    await apiResponse.EnsureSuccessAsync();","typeGuard":null,"tryCatchPattern":"try { await response.EnsureSuccessAsync(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"unavailable\"))\n{\n    // No HTTP response was ever received — rethrow the underlying transport error.\n    throw response.Error ?? ex;\n}","preventionTips":["Inspect ApiResponse.Error before forcing the ApiException path; transport failures have no response.","Handle cancellation and HttpRequestException separately from HTTP error responses.","Don't assume a response always exists — network/transport layers can fail before one arrives."],"tags":["api-response","cancellation","transport-error","error-handling"],"backgroundTag":null,"analyzedSha":"b455f65ecc4c97d092317e349cb775f9cfc6bcdf","analyzedAt":"2026-08-13T21:20:57.878Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}