Skip to content

Commit 05a639d

Browse files
author
Bart Koelman
committed
Revert the use of different exception, because this way the request body does not get added to the error response meta
1 parent 1e1bafa commit 05a639d

File tree

4 files changed

+7
-28
lines changed

4 files changed

+7
-28
lines changed

src/JsonApiDotNetCore/Errors/ForbiddenClientGeneratedIdException.cs

-25
This file was deleted.

src/JsonApiDotNetCore/Serialization/RequestAdapters/ResourceIdentityAdapter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private static void AssertHasNoId(IResourceIdentity identity, RequestAdapterStat
182182
if (identity.Id != null)
183183
{
184184
using IDisposable _ = state.Position.PushElement("id");
185-
throw new ForbiddenClientGeneratedIdException(state.Position.ToSourcePointer());
185+
throw new ModelConversionException(state.Position, "The use of client-generated IDs is disabled.", null, HttpStatusCode.Forbidden);
186186
}
187187
}
188188

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Creating/AtomicCreateResourceTests.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,11 @@ public async Task Cannot_create_resource_with_client_generated_ID()
459459

460460
ErrorObject error = responseDocument.Errors[0];
461461
error.StatusCode.Should().Be(HttpStatusCode.Forbidden);
462-
error.Title.Should().Be("The use of client-generated IDs is disabled.");
462+
error.Title.Should().Be("Failed to deserialize request body: The use of client-generated IDs is disabled.");
463463
error.Detail.Should().BeNull();
464464
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/id");
465+
466+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
465467
}
466468

467469
[Fact]

test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Creating/CreateResourceTests.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,11 @@ public async Task Cannot_create_resource_with_client_generated_ID()
456456

457457
ErrorObject error = responseDocument.Errors[0];
458458
error.StatusCode.Should().Be(HttpStatusCode.Forbidden);
459-
error.Title.Should().Be("The use of client-generated IDs is disabled.");
459+
error.Title.Should().Be("Failed to deserialize request body: The use of client-generated IDs is disabled.");
460460
error.Detail.Should().BeNull();
461461
error.Source.Pointer.Should().Be("/data/id");
462+
463+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
462464
}
463465

464466
[Fact]

0 commit comments

Comments
 (0)