Skip to content

Commit 0f6a75f

Browse files
committed
Removed resource ID from error message, as the error is unrelated to any specific record
1 parent 01b7164 commit 0f6a75f

File tree

4 files changed

+8
-13
lines changed

4 files changed

+8
-13
lines changed

src/JsonApiDotNetCore/Errors/CannotClearRequiredRelationshipException.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ namespace JsonApiDotNetCore.Errors;
1010
[PublicAPI]
1111
public sealed class CannotClearRequiredRelationshipException : JsonApiException
1212
{
13-
public CannotClearRequiredRelationshipException(string relationshipName, string resourceId, string resourceType)
13+
public CannotClearRequiredRelationshipException(string relationshipName, string resourceType)
1414
: base(new ErrorObject(HttpStatusCode.BadRequest)
1515
{
1616
Title = "Failed to clear a required relationship.",
17-
Detail = $"The relationship '{relationshipName}' on resource type '{resourceType}' " +
18-
$"with ID '{resourceId}' cannot be cleared because it is a required relationship."
17+
Detail = $"The relationship '{relationshipName}' on resource type '{resourceType}' cannot be cleared because it is a required relationship."
1918
})
2019
{
2120
}

src/JsonApiDotNetCore/Repositories/EntityFrameworkCoreRepository.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public virtual async Task UpdateAsync(TResource resourceFromRequest, TResource r
269269
object? rightValueEvaluated = await VisitSetRelationshipAsync(resourceFromDatabase, relationship, rightValue, WriteOperationKind.UpdateResource,
270270
cancellationToken);
271271

272-
AssertIsNotClearingRequiredToOneRelationship(relationship, resourceFromDatabase, rightValueEvaluated);
272+
AssertIsNotClearingRequiredToOneRelationship(relationship, rightValueEvaluated);
273273

274274
await UpdateRelationshipAsync(relationship, resourceFromDatabase, rightValueEvaluated, cancellationToken);
275275
}
@@ -288,7 +288,7 @@ public virtual async Task UpdateAsync(TResource resourceFromRequest, TResource r
288288
_dbContext.ResetChangeTracker();
289289
}
290290

291-
protected void AssertIsNotClearingRequiredToOneRelationship(RelationshipAttribute relationship, TResource leftResource, object? rightValue)
291+
protected void AssertIsNotClearingRequiredToOneRelationship(RelationshipAttribute relationship, object? rightValue)
292292
{
293293
if (relationship is HasOneAttribute)
294294
{
@@ -300,7 +300,7 @@ protected void AssertIsNotClearingRequiredToOneRelationship(RelationshipAttribut
300300
if (isRelationshipRequired && isClearingRelationship)
301301
{
302302
string resourceName = _resourceGraph.GetResourceType<TResource>().PublicName;
303-
throw new CannotClearRequiredRelationshipException(relationship.PublicName, leftResource.StringId!, resourceName);
303+
throw new CannotClearRequiredRelationshipException(relationship.PublicName, resourceName);
304304
}
305305
}
306306
}
@@ -403,7 +403,7 @@ public virtual async Task SetRelationshipAsync(TResource leftResource, object? r
403403
object? rightValueEvaluated =
404404
await VisitSetRelationshipAsync(leftResource, relationship, rightValue, WriteOperationKind.SetRelationship, cancellationToken);
405405

406-
AssertIsNotClearingRequiredToOneRelationship(relationship, leftResource, rightValueEvaluated);
406+
AssertIsNotClearingRequiredToOneRelationship(relationship, rightValueEvaluated);
407407

408408
await UpdateRelationshipAsync(relationship, leftResource, rightValueEvaluated, cancellationToken);
409409

test/JsonApiDotNetCoreTests/IntegrationTests/InputValidation/ModelState/NoModelStateValidationTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
128128
ErrorObject error = responseDocument.Errors[0];
129129
error.StatusCode.Should().Be(HttpStatusCode.BadRequest);
130130
error.Title.Should().Be("Failed to clear a required relationship.");
131-
132-
error.Detail.Should().Be($"The relationship 'rootDirectory' on resource type 'systemVolumes' with ID '{existingVolume.StringId}' " +
133-
"cannot be cleared because it is a required relationship.");
131+
error.Detail.Should().Be("The relationship 'rootDirectory' on resource type 'systemVolumes' cannot be cleared because it is a required relationship.");
134132
}
135133
}

test/JsonApiDotNetCoreTests/IntegrationTests/RequiredRelationships/DefaultBehaviorTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
256256
ErrorObject error = responseDocument.Errors[0];
257257
error.StatusCode.Should().Be(HttpStatusCode.BadRequest);
258258
error.Title.Should().Be("Failed to clear a required relationship.");
259-
260-
error.Detail.Should().Be($"The relationship 'customer' on resource type 'orders' with ID '{existingOrder.StringId}' " +
261-
"cannot be cleared because it is a required relationship.");
259+
error.Detail.Should().Be("The relationship 'customer' on resource type 'orders' cannot be cleared because it is a required relationship.");
262260
}
263261

264262
[Fact]

0 commit comments

Comments
 (0)