Skip to content

Commit da9048f

Browse files
authored
Merge pull request #1193 from json-api-dotnet/duplicate-controllers-error
Improve error message when duplicate controllers found
2 parents cdf3c0b + 1dc249b commit da9048f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Diff for: src/JsonApiDotNetCore/Middleware/JsonApiRoutingConvention.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public void Apply(ApplicationModel application)
7878
{
7979
if (_controllerPerResourceTypeMap.ContainsKey(resourceType))
8080
{
81-
throw new InvalidConfigurationException($"Multiple controllers found for resource type '{resourceType}'.");
81+
throw new InvalidConfigurationException(
82+
$"Multiple controllers found for resource type '{resourceType}': '{_controllerPerResourceTypeMap[resourceType].ControllerType}' and '{controller.ControllerType}'.");
8283
}
8384

8485
_resourceTypePerControllerTypeMap.Add(controller.ControllerType, resourceType);

Diff for: test/JsonApiDotNetCoreTests/IntegrationTests/NonJsonApiControllers/DuplicateResourceControllerTests.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public void Fails_at_startup_when_multiple_controllers_exist_for_same_resource_t
2020
Action action = () => _ = Factory;
2121

2222
// Assert
23-
action.Should().ThrowExactly<InvalidConfigurationException>().WithMessage("Multiple controllers found for resource type 'knownResources'.");
23+
InvalidConfigurationException exception = action.Should().ThrowExactly<InvalidConfigurationException>().Which!;
24+
exception.Message.Should().StartWith("Multiple controllers found for resource type 'knownResources': ");
25+
exception.Message.Should().Contain($"'{typeof(KnownResourcesController).FullName}'");
26+
exception.Message.Should().Contain($"'{typeof(DuplicateKnownResourcesController).FullName}'");
2427
}
2528
}

0 commit comments

Comments
 (0)