Skip to content

Commit

Permalink
Do not attempt to parse response bodies on HTTP 204
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianeicher committed Jul 6, 2024
1 parent 3ce1630 commit 9c3b36f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/TypedRest/Endpoints/Generic/ElementEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ public virtual async Task DeleteAsync(CancellationToken cancellationToken = defa

private async Task<TEntity?> TryReadAsAsync(HttpResponseMessage response, CancellationToken cancellationToken)
{
if (response.StatusCode == HttpStatusCode.NoContent) return null;

try
{
return await response.Content.ReadAsAsync<TEntity?>(Serializers, cancellationToken).NoContext();
Expand Down
2 changes: 1 addition & 1 deletion src/TypedRest/Http/ResponseCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed class ResponseCache
/// </summary>
/// <returns>The <see cref="ResponseCache"/>; <c>null</c> if the response is not eligible for caching.</returns>
public static ResponseCache? From(HttpResponseMessage response)
=> response is {IsSuccessStatusCode: true, Headers.CacheControl: null or {NoStore: false}}
=> response is {IsSuccessStatusCode: true, StatusCode: not HttpStatusCode.NoContent, Headers.CacheControl: null or {NoStore: false}}
? new(response)
: null;

Expand Down

0 comments on commit 9c3b36f

Please sign in to comment.