/// <summary>
        /// Creates the validation error message.
        /// </summary>
        /// <param name="result">The validation result.</param>
        /// <returns>An error based on validation result</returns>
        private JudoApiErrorModel CreateValidationErrorMessage(ValidationResult result)
        {
            if (result.IsValid)
            {
                return(null);
            }

            var invalidRequestModel = new JudoApiErrorModel
            {
                ErrorType    = JudoApiError.General_Model_Error,
                ErrorMessage = "Invalid request",
                ModelErrors  = new List <JudoModelError>(result.Errors.Count)
            };

            foreach (var validationFailure in result.Errors)
            {
                _logger.DebugFormat("Model validation error {0} {1}", validationFailure.PropertyName, validationFailure.ErrorMessage);
                invalidRequestModel.ModelErrors.Add(new JudoModelError
                {
                    FieldName    = validationFailure.PropertyName,
                    ErrorMessage = validationFailure.ErrorMessage
                });
            }

            return(invalidRequestModel);
        }
Пример #2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var jsonObject = JObject.Load(reader);
            var properties = jsonObject.Properties().ToList();
            var oldNames   = new [] { "errormessage", "errortype", "modelerrors" };
            var judoApiErrorModelPropertiesNames = new[] { "details", "messages", "code", "category" };



            if (judoApiErrorModelPropertiesNames.Any(p => properties.Select(t => t.Name.ToLower()).Contains(p.ToLower())))
            {
                var modelError = new ModelError()
                {
                    ModelErrors = GetProperty <List <FieldError> >(serializer, properties, "details"),
                    Code        = GetProperty <int>(serializer, properties, "code"),
                    Category    = GetProperty <string>(serializer, properties, "category"),
                    Message     = GetProperty <string>(serializer, properties, "message"),
                };
                return(modelError);
            }

            if (oldNames.Any(p => properties.Select(t => t.Name.ToLower()).Contains(p.ToLower())))
            {
                var errorType = GetProperty <int>(serializer, properties, "errortype");
                var error     = JudoApiError.General_Error;

                if (Enum.IsDefined(typeof(JudoApiError), errorType))
                {
                    error = (JudoApiError)errorType;
                }
                else
                {
                    _log.InfoFormat("The JudoApiError {0} was sent by the server and it is not recognized by the SDK", errorType);
                }

                var modelError = new JudoApiErrorModel()
                {
                    ErrorMessage = GetProperty <string>(serializer, properties, "errormessage"),
                    ErrorType    = error,
                    ModelErrors  = GetProperty <List <JudoModelError> >(serializer, properties, "modelerrors")
                };
                return(modelError);
            }
            if (properties.Any(t => t.Name == "message"))
            {
                return(new ModelError()
                {
                    Message = GetProperty <string>(serializer, properties, "message"),
                    Code = 0
                });
            }
            return(new ModelError()
            {
                Message = "Unknown Return type",
                Code = 0
            });
        }
Пример #3
0
 public Result(T response, JudoApiErrorModel error) : base(error)
 {
     Response = response;
 }
Пример #4
0
        internal static Intent CreateErrorIntent(string message, Exception exception, JudoApiErrorModel apiErrorModel)
        {
            Intent intent = new Intent();

            intent.PutExtra(JUDO_ERROR_MESSAGE, message);
            intent.PutExtra(JUDO_ERROR_EXCEPTION, JsonConvert.SerializeObject(new JudoError(exception, apiErrorModel)));

            return(intent);
        }
Пример #5
0
 public JudoError(Exception exception, JudoApiErrorModel apiError)
 {
     Exception = exception;
     ApiError  = apiError;
 }