using FluentValidation.Results; namespace cuqmbr.TravelGuide.Application.Common.Exceptions; public class ValidationException : Exception { public ValidationException() : base("One or more validation failures have occurred.") { Errors = new Dictionary(); } public ValidationException(string message) : base(message) { Errors = new Dictionary(); } public ValidationException(IEnumerable failures) : this() { // TODO: Make serialized dictionary look more like this // "errors": { // "viewModel": [ // "The viewModel field is required." // ], // "$.addresses[0].order": [ // "The JSON value could not be converted to System.Int16. Path: $.addresses[0].order | LineNumber: 5 | BytePositionInLine: 26." // ] // }, Errors = failures .GroupBy(f => f.PropertyName, f => f.ErrorMessage) .ToDictionary(fg => fg.Key, fg => fg.ToArray()); } public IDictionary Errors { get; } }