2015-12-08 22:57:38 -05:00
|
|
|
|
using System;
|
2016-05-19 19:10:24 -04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
2015-12-08 22:57:38 -05:00
|
|
|
|
|
|
|
|
|
|
namespace Bit.Core.Exceptions
|
|
|
|
|
|
{
|
|
|
|
|
|
public class BadRequestException : Exception
|
|
|
|
|
|
{
|
2019-03-01 17:30:44 -05:00
|
|
|
|
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.")
|
|
|
|
|
|
{
|
2020-03-27 14:36:37 -04:00
|
|
|
|
if (modelState.IsValid || modelState.ErrorCount == 0)
|
2015-12-08 22:57:38 -05:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ModelState = modelState;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ModelStateDictionary ModelState { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|