private static ApiExceptionData GetExceptionData(ApiSecurityErrors error, string message = null, Exception details = null) { Type type = error.GetType(); Array values = System.Enum.GetValues(type); foreach (int val in values) { if (val == (int)error) { var memInfo = type.GetMember(type.GetEnumName(val)); var att = memInfo[0] .GetCustomAttributes(typeof(SecurityErrorDetailsAttribute), false) .FirstOrDefault() as SecurityErrorDetailsAttribute; if (att != null) { var retVal = new ApiExceptionData(); retVal.StatusCode = att.StatusCode; retVal.Code = att.Code; retVal.Message = message ?? att.Message; retVal.Details = details == null ? null : details.Message; return(retVal); } } } throw new Exception("The specified SecurityErrorDetailsAttribute was not found"); }
public ApiSecurityException(ApiSecurityErrors error, string message = null, Exception details = null) : base(GetExceptionData(error, message, details)) { }