using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Mvc.ModelBinding; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Wood.Util { public static partial class Extensions { public static Exception GetOriginalException(this Exception ex) { if (ex.InnerException == null) return ex; return ex.InnerException.GetOriginalException(); } public static string GetFullExceptionMessage(this Exception ex) { StringBuilder sbException = new StringBuilder(); Exception exception = ex; sbException.AppendLine(exception.Message); while (exception.InnerException != null) { sbException.AppendLine(exception.InnerException.Message); exception = exception.InnerException; } return sbException.ToString(); } public static List GetAllErrorMessages(this ModelStateDictionary modelState) { var errors = new List(); foreach (var state in modelState) { foreach (var error in state.Value.Errors) { errors.Add(error.ErrorMessage); } } return errors; } } }