Skip to content

Commit 477b55d

Browse files
author
Bart Koelman
authored
Merge pull request #762 from bart-degreed/fix-kestrel-error-on-delete
Fixed: exception logged in Kestrel on Delete request
2 parents ac5b100 + 583f76f commit 477b55d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/JsonApiDotNetCore/Formatters/JsonApiWriter.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,19 @@ private string SerializeResponse(object contextObject, HttpStatusCode statusCode
7777
throw new UnsuccessfulActionResultException(problemDetails);
7878
}
7979

80-
if (contextObject == null && !IsSuccessStatusCode(statusCode))
80+
if (contextObject == null)
8181
{
82-
throw new UnsuccessfulActionResultException(statusCode);
82+
if (!IsSuccessStatusCode(statusCode))
83+
{
84+
throw new UnsuccessfulActionResultException(statusCode);
85+
}
86+
87+
if (statusCode == HttpStatusCode.NoContent || statusCode == HttpStatusCode.ResetContent ||
88+
statusCode == HttpStatusCode.NotModified)
89+
{
90+
// Prevent exception from Kestrel server, caused by writing data:null json response.
91+
return null;
92+
}
8393
}
8494

8595
contextObject = WrapErrors(contextObject);

test/NoEntityFrameworkTests/WorkItemTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ await ExecuteOnDbContextAsync(async dbContext =>
146146
string responseBody = await response.Content.ReadAsStringAsync();
147147
var document = JsonConvert.DeserializeObject<Document>(responseBody);
148148

149-
Assert.Null(document.Data);
149+
Assert.Null(document);
150150
}
151151

152152
private async Task ExecuteOnDbContextAsync(Func<AppDbContext, Task> asyncAction)

0 commit comments

Comments
 (0)