Esempio n. 1
0
        public override void OnException(HttpActionExecutedContext context)
        {
            _logger.WriteError(context.Exception, LogCategories);
            HttpResponseMessage           responseMessage = new HttpResponseMessage(HttpStatusCode.BadRequest);
            List <ValidationMessageModel> messages        = new List <ValidationMessageModel>();
            ValidationModel model          = new ValidationModel();
            int             validationCode = (int)DSWExceptionCode.Invalid;

            responseMessage.ReasonPhrase = null;
            responseMessage.StatusCode   = HttpStatusCode.BadRequest;
            if (context.Exception is DSWException)
            {
                DSWException ex = context.Exception as DSWException;

                messages.Add(new ValidationMessageModel()
                {
                    Message = ex.Message, MessageCode = (int)ex.ExceptionCode
                });
            }
            else
            {
                messages = FillRecursive(context.Exception, messages, validationCode);
            }

            model.ValidationCode     = validationCode;
            model.ValidationMessages = new ReadOnlyCollection <ValidationMessageModel>(messages);
            responseMessage.Content  = new StringContent(JsonConvert.SerializeObject(model, JsonSerializerConfig.SerializerSettings));

            context.Response = responseMessage;
        }
Esempio n. 2
0
 public DSWValidationException(Type type, string message, IReadOnlyCollection <ValidationMessageModel> validationMessages, DSWException innerException, DSWExceptionCode exceptionCode)
     : this(string.Concat(type.AssemblyQualifiedName, message), validationMessages, innerException, exceptionCode)
 {
 }
Esempio n. 3
0
 public DSWValidationException(string message, IReadOnlyCollection <ValidationMessageModel> validationMessages,
                               DSWException innerException, DSWExceptionCode exceptionCode)
     : base(message, innerException, exceptionCode)
 {
     _validationMessages = validationMessages ?? new ReadOnlyCollection <ValidationMessageModel>(new List <ValidationMessageModel>());
 }