8000 ApiResponse<T> tries to deserealize response even for non-success codes · Issue #537 · reactiveui/refit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
ApiResponse<T> tries to deserealize response even for non-success codes #537
Closed
@viktor-nikolaev

Description

@viktor-nikolaev

I don't know if it is by design, but it makes impossible to deserialize error in response - because the RequestBuilderImplementation,BuildCancellableTaskFuncForMethod already closed the response stream.

With such a behavior this issue #531 can't be done using ApiResponse as suggested here

btw it's not so cool to get the error using try-catch (see the code)

public static async Task<TError> GetErrorAsync<TResponse, TError>(this ApiResponse<TResponse> apiResponse)
{
  if (!apiResponse.IsSuccessStatusCode)
  {
    try
    {
      await apiResponse.EnsureSuccessStatusCodeAsync().ConfigureAwait(false);
    }
    catch (ApiException e)
    {
      var errorAsync = e.GetContentAs<TError>();
      return errorAsync;
    }
  }

  return default(TError);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0