Try catch alternative for HTTP request

Hello,

When connecting to a REST api, randomly and in some android devices I get errors when doing a POST. The errors are allways Curl error… and they usually appear when the users are connected to free wifis and probably with wifis with extra security.

The issue is that when the error appear, the coroutine crashes, and fails, It doesnt return a http or network error and I am being unable to control the crashes because I cant use try catch with a return statement inside.

        using (var request = new UnityWebRequest(string.Concat(server, url, applications, id, refreshToken), "POST"))
        {
            byte[] bodyRaw = Encoding.UTF8.GetBytes(form);
            request.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
            request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
            request.SetRequestHeader("Content-Type", "application/json");
            request.SetRequestHeader("Authorization", "Bearer " + loginInfo.data.access_token);
            
            yield return request.SendWebRequest();

Hey,

only thing i could think of at the top of my head would be to investigate if changing from Coroutines to an async function can be done here using something like this Webrequest Wrapper here (GitHubLink)

If i remember correctly you can add try catches around a complete async function which makes it superior in this case.