mirror of
https://github.com/bitwarden/server.git
synced 2025-06-07 19:50:32 -05:00

* Enable NRT for Core/Jobs files * Enable NRT for Core/HostedServices files * Enable NRT for Core/Exceptions files * Enable NRT for Core/NotificationHub files --------- Co-authored-by: Bernd Schoolmann <mail@quexten.com>
48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
|
|
|
namespace Bit.Core.Exceptions;
|
|
|
|
#nullable enable
|
|
|
|
public class BadRequestException : Exception
|
|
{
|
|
public BadRequestException() : base()
|
|
{ }
|
|
|
|
public BadRequestException(string message)
|
|
: base(message)
|
|
{ }
|
|
|
|
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 BadRequestException(IEnumerable<IdentityError> identityErrors)
|
|
: base("The model state is invalid.")
|
|
{
|
|
ModelState = new ModelStateDictionary();
|
|
|
|
foreach (var error in identityErrors)
|
|
{
|
|
ModelState.AddModelError(error.Code, error.Description);
|
|
}
|
|
}
|
|
|
|
public ModelStateDictionary? ModelState { get; set; }
|
|
}
|