Tuesday, April 17, 2018

Get proper error message when webRequest.GetResponse failed (status code 500)

Right now i am working on bitcoin core wallet application when ever i send request on http request if it is failed it always return
500 status code not a meaning full error message so after googling i found this so i can easily trace
out at what reason it send failed.


after try block  add this

 catch (WebException ex)
            {
                using (var stream = ex.Response.GetResponseStream())
                using (var reader = new StreamReader(stream))
                {
                    var error = reader.ReadToEnd();
                    CustomLogger.Log("Custom Error Desc: " + Convert.ToString(error));

                }
           
            }

ref:

Link for help

No comments:

Post a Comment