2015-12-09 04:57:38 +01:00
|
|
|
|
using System;
|
2016-05-20 01:10:24 +02:00
|
|
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
2015-12-09 04:57:38 +01:00
|
|
|
|
|
|
|
|
|
namespace Bit.Core.Exceptions
|
|
|
|
|
{
|
|
|
|
|
public class BadRequestException : Exception
|
|
|
|
|
{
|
2019-03-01 23:30:44 +01:00
|
|
|
|
public BadRequestException(string message)
|
|
|
|
|
: base(message)
|
|
|
|
|
{ }
|
2015-12-09 04:57:38 +01: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.")
|
|
|
|
|
{
|
|
|
|
|
if(modelState.IsValid || modelState.ErrorCount == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ModelState = modelState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ModelStateDictionary ModelState { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|