protected T ExecuteRESTRequest <T>(CloudIdentity identity, string urlPath, HttpMethod method, object body, Dictionary <string, string> queryStringParameter, bool isRetry, bool isTokenRequest, string token, int retryCount, int retryDelay, Func <Uri, HttpMethod, string, Dictionary <string, string>, Dictionary <string, string>, JsonRequestSettings, T> callback) where T : Response { if (identity == null) { identity = _defaultIdentity; } var url = new Uri(_urlBase, urlPath); var headers = new Dictionary <string, string>(); if (!isTokenRequest) { headers.Add("X-Auth-Token", string.IsNullOrWhiteSpace(token) ? GetToken(identity) : token); } string bodyStr = null; if (body != null) { if (body is JObject) { bodyStr = body.ToString(); } else { bodyStr = JsonConvert.SerializeObject(body, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); } } var settings = new JsonRequestSettings() { RetryCount = retryCount, RetryDelayInMS = retryDelay, Non200SuccessCodes = new[] { 401, 409 }, UserAgent = UserAgentGenerator.Generate() }; var response = callback(url, method, bodyStr, headers, queryStringParameter, settings); // on errors try again 1 time. if (response.StatusCode == 401 && !isRetry && !isTokenRequest) { return(ExecuteRESTRequest <T>(identity, urlPath, method, body, queryStringParameter, true, isTokenRequest, GetToken(identity), retryCount, retryCount, callback)); } _responseCodeValidator.Validate(response); return(response); }
internal void CheckResponse(Response response) { ResponseCodeValidator.Validate(response); }