public async Task <SubGlRespObj> GetAllSubglAsync() { try { var gosGatewayClient = _httpClientFactory.CreateClient("GOSDEFAULTGATEWAY"); string authorization = _accessor.HttpContext.Request.Headers["Authorization"]; gosGatewayClient.DefaultRequestHeaders.Add("Authorization", authorization); var response = new SubGlRespObj { Status = new APIResponseStatus { IsSuccessful = true, Message = new APIResponseMessage() } }; SubGlRespObj resultObj = new SubGlRespObj(); var result = await gosGatewayClient.GetAsync(ApiRoutes.CreditServerEndpoint.SUB_GLS); var resultString = await result.Content.ReadAsStringAsync(); resultObj = JsonConvert.DeserializeObject <SubGlRespObj>(resultString); if (!result.IsSuccessStatusCode) { response.Status.IsSuccessful = false; response.Status.Message.FriendlyMessage = $"{result.ReasonPhrase} {(int)result.StatusCode} {result.Content}"; throw new Exception($"{response}"); } if (!resultObj.Status.IsSuccessful) { response.Status = resultObj.Status; return(response); } response.SubGls = resultObj.SubGls; return(response); } catch (Exception ex) { #region Log error var errorCode = ErrorID.Generate(4); _logger.Error($"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}"); throw ex; #endregion } }
public async Task <SubGlRespObj> GetAllSubGlAsync() { var gosGatewayClient = _httpClientFactory.CreateClient("GOSDEFAULTGATEWAY"); string authorization = _accessor.HttpContext.Request.Headers["Authorization"]; gosGatewayClient.DefaultRequestHeaders.Add("Authorization", authorization); SubGlRespObj responseObj = new SubGlRespObj(); return(await _retryPolicy.ExecuteAsync(async() => { try { result = await gosGatewayClient.GetAsync(ApiRoutes.SubGl.GET_ALL_SUBGL); if (!result.IsSuccessStatusCode) { var data1 = await result.Content.ReadAsStringAsync(); responseObj = JsonConvert.DeserializeObject <SubGlRespObj>(data1); new SubGlRespObj { Status = new APIResponseStatus { Message = new APIResponseMessage { FriendlyMessage = result.ReasonPhrase } } }; } var data = await result.Content.ReadAsStringAsync(); responseObj = JsonConvert.DeserializeObject <SubGlRespObj>(data); } catch (Exception ex) { throw ex; } if (responseObj == null) { return new SubGlRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "System Error!! Please contact Administrator" } } }; } if (!responseObj.Status.IsSuccessful) { return new SubGlRespObj { Status = new APIResponseStatus { IsSuccessful = responseObj.Status.IsSuccessful, Message = responseObj.Status.Message } }; } return new SubGlRespObj { subGls = responseObj.subGls, Status = new APIResponseStatus { IsSuccessful = responseObj.Status.IsSuccessful, Message = responseObj.Status.Message } }; })); }