public override void OnActionExecuting(ActionExecutingContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } else if (!context.ModelState.IsValid) { String errorMessage = ErrorUtilities.BuildErrorMessage(GetModelStateErrors(context)); ApiError apiError = new ApiError(errorMessage) { Detail = null }; context.HttpContext.Response.StatusCode = 400; _logger.LogError("HTTP status code 400 occurred. " + errorMessage); context.Result = new JsonResult(apiError); } }