You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

50 lines
1.4 KiB

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<string> GetAllErrorMessages(this ModelStateDictionary modelState)
{
var errors = new List<string>();
foreach (var state in modelState)
{
foreach (var error in state.Value.Errors)
{
errors.Add(error.ErrorMessage);
}
}
return errors;
}
}
}