36 lines
1014 B
C#
36 lines
1014 B
C#
namespace Indotalent.ConfigBackEnd.Exceptions;
|
|
|
|
using FluentValidation.Results;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
public class ValidationException : Exception
|
|
{
|
|
public IDictionary<string, string[]> Errors { get; }
|
|
|
|
public ValidationException()
|
|
: base("One or more validation failures have occurred.")
|
|
{
|
|
Errors = new Dictionary<string, string[]>();
|
|
}
|
|
|
|
public ValidationException(IEnumerable<ValidationFailure> failures)
|
|
: this()
|
|
{
|
|
Errors = failures
|
|
.GroupBy(e => e.PropertyName, e => e.ErrorMessage)
|
|
.ToDictionary(failureGroup => failureGroup.Key, failureGroup => failureGroup.ToArray());
|
|
}
|
|
|
|
public ValidationException(string message)
|
|
: base(message)
|
|
{
|
|
Errors = new Dictionary<string, string[]>();
|
|
}
|
|
|
|
public ValidationException(string message, Exception innerException)
|
|
: base(message, innerException)
|
|
{
|
|
Errors = new Dictionary<string, string[]>();
|
|
}
|
|
} |