evemon icon indicating copy to clipboard operation
evemon copied to clipboard

Improvement for HttpClientServiceRequest.EnsureSuccessStatusCode to simplyfy debugging ESI

Open wvdvegt opened this issue 3 years ago • 1 comments

In 'src\EVEMon.Common\Net\HttpClientServiceRequest.cs', I replaced the EnsureSuccessStatusCode method by the version below that outputs traces (seen in the VS output window) when ESI requests fail.

As the new code shows the request uri and response content it greatly simplyfies finding ESI endpoints that fail.

        private static void EnsureSuccessStatusCode(HttpResponseMessage response)
        {
            var code = response.StatusCode;
            if ((int)code < 100)
            {
                response.StatusCode = HttpStatusCode.OK;
                response.ReasonPhrase = "OK";
            }
            else if (code != HttpStatusCode.NotModified)
            {
                if (response.RequestMessage.RequestUri.ToString().StartsWith(NetworkConstants.ESIBase) && !response.IsSuccessStatusCode)
                {
                    String body = response.Content.ReadAsStringAsync().Result;

                    EveMonClient.Trace($"Request: {response.RequestMessage.RequestUri} returned: {(Int32)response.StatusCode} ({response.ReasonPhrase}) with content: '{body}'.", printMethod: false);
                }

                // Allow "not modified" so that it will be detected by the front end
                response.EnsureSuccessStatusCode();
            }
        }

wvdvegt avatar Oct 27 '21 11:10 wvdvegt

can you add all last changes to your fork?

dreamer2 avatar Oct 27 '21 18:10 dreamer2