Skip to content

Commit 6a2f968

Browse files
author
Chris Santero
committed
provide more helpful error when the resource ID is null
1 parent 7f6431f commit 6a2f968

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

JSONAPI/Core/ResourceTypeRegistration.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ internal ResourceTypeRegistration(Type type, PropertyInfo idProperty, string res
4747
public string GetIdForResource(object resource)
4848
{
4949
if (resource == null) throw new ArgumentNullException(nameof(resource));
50-
return IdProperty.GetValue(resource).ToString();
50+
var resourceId = IdProperty.GetValue(resource);
51+
if (resourceId == null) throw new ArgumentException($"The ID for the provided `{ResourceTypeName}` resource is null.");
52+
return resourceId.ToString();
5153
}
5254

5355
public void SetIdForResource(object resource, string id)

0 commit comments

Comments
 (0)