Multi errors
The json api spec allows an array of errors, but currently this isn't supported here. This would be a useful addition.
Agreed! Thanks for commenting. Most errors coming out of .NET are single exceptions but there does need to be a way for a user to add more error messages onto the output.
The way I dealt with this was to create up a new CustomJsonApiActionFilter that inherits JsonApiActionFilter. I then override OnActionExecuted to return MultiErrorResult immediately if it's found:
public override void OnActionExecuted(ActionExecutedContext context)
{
if (context.Result == null || context.Result is MultiErrorResult)
{
return;
}
base.OnActionExecuted(context);
}
MultiErrorResult is simply an ObjectResult that was created to have the same format as the JsonApi calls for:
public class MultiErrorResult : ObjectResult
{
public MultiErrorResult(List<Error> errors) : base(null)
{
StatusCode = (int) HttpStatusCode.BadRequest;
Value = new {errors = errors};
}
}
I now can use MultiErrorResult to return validation errors as needed. I get that CustomJsonApiActionFilter is kinda a hack, but I have not yet had time to put together a pull request.