Files
server/src/Core/Exceptions/BadRequestException.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
751 B
C#
Raw Normal View History

using Microsoft.AspNetCore.Mvc.ModelBinding;
2015-12-08 22:57:38 -05:00
namespace Bit.Core.Exceptions;
2022-08-29 14:53:16 -04:00
2015-12-08 22:57:38 -05:00
public class BadRequestException : Exception
{
public BadRequestException(string message)
: base(message)
{ }
2015-12-08 22:57:38 -05:00
public BadRequestException(string key, string errorMessage)
: base("The model state is invalid.")
{
ModelState = new ModelStateDictionary();
ModelState.AddModelError(key, errorMessage);
}
public BadRequestException(ModelStateDictionary modelState)
: base("The model state is invalid.")
2022-08-29 14:53:16 -04:00
{
if (modelState.IsValid || modelState.ErrorCount == 0)
2015-12-08 22:57:38 -05:00
{
return;
}
ModelState = modelState;
}
2022-08-29 14:53:16 -04:00
2015-12-08 22:57:38 -05:00
public ModelStateDictionary ModelState { get; set; }
}