示例#1
0
        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");
        }
示例#2
0
        private static ApiExceptionData GetExceptionData(ModelStateDictionary context)
        {
            var errors = context.Where(e => e.Value.Errors.Count > 0)
                         .Select(e => new { Name = e.Key, Message = e.Value.Errors.First().ErrorMessage })
                         .ToArray();

            var retVal = new ApiExceptionData();

            retVal.StatusCode = 400;
            retVal.Code       = "INVALID_MODEL";
            retVal.Message    = "The model is invalid";
            retVal.Details    = errors;
            return(retVal);
        }
示例#3
0
 public ApiException(ApiExceptionData data) : base(data.Message)
 {
     StatusCode = data.StatusCode;
     Code       = data.Code;
     Details    = data.Details;
 }