locked
waiting for response from API need to be modified RRS feed

  • Question

  • User-1660589204 posted

    I have a piece of code in which I get a response from API( takes some time from API to send response). So, I went for an if condition to check for response which does not seem to be a good idea. Can anyone help me with a better coding for the below code:

     public async Task<string> JobStatus(string accessToken, RsbfileDetails objRsbfileDetail)
            {
                try
                {
                    TranceCodeAllData objFileUpload = null;
                    string createEndPointURL = url + "/job/status";
                    HttpClient client = Method_Headers(accessToken, createEndPointURL);
                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, client.BaseAddress);
                    MultipartFormDataContent form = new MultipartFormDataContent();
                    form.Add(new StringContent(objRsbfileDetail.TranscriptionJobId), "jobId");
                    HttpResponseMessage tokenResponse = client.PostAsync(createEndPointURL, form).Result;
                    string result = tokenResponse.Content.ReadAsStringAsync().Result;
                    objFileUpload = tokenResponse.Content.ReadAsAsync<TranceCodeAllData>().Result;
                    if (tokenResponse.IsSuccessStatusCode)
                    {
                        objRsbfileDetail.FileTranscodeJobId = objFileUpload.data.jobId;
                        if (objFileUpload.data.status != "COMPLETED")
                        {
                            JobStatus( accessToken,  objRsbfileDetail);
                        }
                        else
                        {
                            objRsbfileDetail.Status = objFileUpload.data.status;
                            JobResult(accessToken, objRsbfileDetail);
                        }
                    }
                }
                catch (HttpRequestException ex)
                {
    
                }
                return "";
            }

    The code is highlighted in yellow. Is there a LINQ statement or a better way to do it? Please help me with it.

    Friday, November 27, 2020 5:44 PM

All replies