// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace System.Web.Http { /// /// An action result that returns a response and performs /// content negotiation on an with a . /// public class BadRequestErrorMessageResult : ObjectResult { /// Initializes a new instance of the class. /// The user-visible error message. public BadRequestErrorMessageResult(string message) : base(new HttpError(message)) { if (message == null) { throw new ArgumentNullException(nameof(message)); } Message = message; } /// /// Gets the error message. /// public string Message { get; private set; } /// public override Task ExecuteResultAsync(ActionContext context) { context.HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest; return base.ExecuteResultAsync(context); } } }