riskfirst / riskfirst.hateoas

Powerful HATEOAS functionality for .NET web api
MIT License
78 stars 25 forks source link

Incorrectly configured route causes a NRE from LinksTransformationBuilder.AddRoutePath #4

Closed jamiecoh closed 7 years ago

jamiecoh commented 7 years ago

An incorrectly configured route, for example badly defined parameters

// Note: id in attr vs myObjectId as param name
[HttpGet("{id:int}",Name="MyBadRoute")
public async Task<MyObject> GetMyObject(int myObjectId)
{
}

And routed via RequiresRoutedLink

options.AddPolicy<MyObject>(policy => policy.RequiresRoutedLink("blah","MyBadRoute",x => new {myObjectId = x.MyObjectId});

Will cause a NullReferenceException due to GetVirtualPath returning null in LinksTransformationBuilderExtensions

...
var virtualPathData = ctx.Router.GetVirtualPath(virtualPathContext);
return virtualPathData.VirtualPath;
jamiecoh commented 7 years ago

Intention is to improve error handling around transformation and raising a more meaningful error. I dont think anyone would want this situation to succeed (ie, give a partial link back) so errors during transformation will raise a LinkTransformationException.