Skip to content

Improve error handling if entity has not been defined on the ContextGraph #182

Closed
@jaredcnance

Description

@jaredcnance

blows up with:

fail: JsonApiDotNetCore.Middleware.JsonApiExceptionFilter[0]
      An unhandled exception occurred during the request
System.NullReferenceException: Object reference not set to an instance of an object.
   at JsonApiDotNetCore.Services.JsonApiContext.ApplyContext[T](Object controller)
   at JsonApiDotNetCore.Controllers.BaseJsonApiController`2..ctor(IJsonApiContext jsonApiContext, IGetAllService`2 getAll, IGetByIdService`2 getById, IGetRelationshipService`2 getRelationship, IGetRelationshipsService`2 getRelationships, ICreateService`2 create, IUpdateService`2 update, IUpdateRelationshipService`2 updateRelationships, IDeleteService`2 delete)
   at N2JsonApi.Web.Domain.PendingItemChanges.PendingItemChangesController..ctor(IJsonApiContext jsonApiContext, IGetAllService`2 getAll) in /Users/michellesantarsiero/dev/n2-jsonapi/src/N2JsonApi.Web/Domain/PendingItemChanges/PendingItemChangesController.cs:line 20
   at lambda_method(Closure , IServiceProvider , Object[] )
   at Microsoft.AspNetCore.Mvc.Internal.TypeActivatorCache.CreateInstance[TInstance](IServiceProvider serviceProvider, Type implementationType)
   at Microsoft.AspNetCore.Mvc.Controllers.DefaultControllerFactory.CreateController(ControllerContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextExceptionFilterAsync>d__24.MoveNext()

RequestEntity = ContextGraph.GetContextEntity(typeof(T));
if (context.Request.Query.Any())
{
QuerySet = new QuerySet(this, context.Request.Query);
IncludedRelationships = QuerySet.IncludedRelationships;
}
var linkBuilder = new LinkBuilder(this);
BasePath = linkBuilder.GetBasePath(context, RequestEntity.EntityName);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions