Skip to content

Commit

Permalink
Add content of response to Error
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSmoke committed Jan 12, 2024
1 parent 9ca6100 commit 57b9124
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/RestClient/RestClient/src/Error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public Error(HttpStatusCode httpStatusCode, ErrorBody body)
}

public HttpStatusCode HttpStatusCode { get; }
public string Content { get; set; }
public ErrorBody Body { get; }
}
}
14 changes: 7 additions & 7 deletions src/RestClient/RestClient/src/Requests/BaseRestClientRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ protected async Task<Error> GetErrorAsync(HttpResponseMessage message)
if (message.IsSuccessStatusCode)
return null;

if (message.Content != null)
{
var content = await message.Content.ReadAsStringAsync().ConfigureAwait(false);
var contentString = await message.Content.ReadAsStringAsync().ConfigureAwait(false);

if (TryParseErrorBody(content, out var errorBody))
return new Error(message.StatusCode, errorBody);
}
if (!TryParseErrorBody(contentString, out var errorBody))
errorBody = GetDefaultErrorBody(message.StatusCode, message.ReasonPhrase);

return new Error(message.StatusCode, GetDefaultErrorBody(message.StatusCode, message.ReasonPhrase));
return new Error(message.StatusCode, errorBody)
{
Content = contentString
};
}

protected virtual void HandleError(Error error)
Expand Down

0 comments on commit 57b9124

Please sign in to comment.