Ejemplo n.º 1
0
 private static ValidationErrorCollection BuildValidationErrorCollection(ErrorBlock errorBlock, ValidationErrorFactory errorFactory, ValidationErrorCollectionFactory errorCollectionFactory, List <string> path)
 {
     return(errorCollectionFactory(path, errorBlock.Errors == null ? new List <ValidationError>() : errorBlock.Errors.Select(error => errorFactory(path, error.Code, error.Format, error.Args)),
                                   errorBlock.Contents == null
             ? new List <KeyValuePair <string, ValidationErrorCollection> >()
             : errorBlock.Contents.Select(
                                       entry => new KeyValuePair <string, ValidationErrorCollection>(entry.Key,
                                                                                                     BuildValidationErrorCollection(entry.Value, errorFactory, errorCollectionFactory, path.Append(entry.Key).ToList())))));
 }
Ejemplo n.º 2
0
 public static ValidationException ToValidationException(this API.CommonJson.ErrorResponse errorResponse, ValidationErrorFactory errorFactory = null, ValidationErrorCollectionFactory errorCollectionFactory = null)
 {
     return(new ValidationException(errorResponse.Message, errorResponse.Code, errorResponse.Details.ToValidationErrorCollection(errorFactory, errorCollectionFactory)));
 }
Ejemplo n.º 3
0
 public static RequestException ToRequestException(this ConnectionResponseException connectionException, string message, object request, ValidationErrorFactory errorFactory = null, ValidationErrorCollectionFactory errorCollectionFactory = null)
 {
     using (var response = connectionException.Response)
     {
         RequestException ex;
         if (response.Code == 500)
         {
             string content;
             try
             {
                 var error = response.ReadAsStreamAsync();
                 error.Wait();
                 using (var streamReader = new StreamReader(error.Result))
                 {
                     content = streamReader.ReadToEnd();
                 }
             }
             catch (Exception e)
             {
                 content = $"Error reading error content: {e.Message}";
             }
             ex = new RequestException($"Internal Server Error: {message}{Environment.NewLine}{content}");
             ex.Data["request"] = request;
             return(ex);
         }
         else
         {
             try
             {
                 var error = response.ReadAsync <API.CommonJson.ErrorResponse>();
                 error.Wait();
                 ex = error.Result.ToValidationException(errorFactory, errorCollectionFactory);
                 ex.Data["request"] = request;
             }
             catch (AggregateException e)
             {
                 ex = new RequestException($"Unexpected Response format. Http Code {response.Code}. {message}", e.InnerException);
                 ex.Data["request"] = request;
             }
         }
         return(ex);
     }
 }
Ejemplo n.º 4
0
        public static ValidationErrorCollection ToValidationErrorCollection(this API.CommonJson.ErrorBlock errorBlock, ValidationErrorFactory errorFactory = null, ValidationErrorCollectionFactory errorCollectionFactory = null)
        {
            if (errorFactory == null)
            {
                errorFactory = ValidationError.Create;
            }
            if (errorCollectionFactory == null)
            {
                errorCollectionFactory = ValidationErrorCollection.Create;
            }

            return(BuildValidationErrorCollection(errorBlock, errorFactory, errorCollectionFactory, new List <string> {
            }));
        }