peterhaneve / evemon

A lightweight, easy-to-use standalone Windows application designed to assist you in keeping track of your EVE Online character progression.
310 stars 72 forks source link

Improvement for HttpClientServiceRequest.EnsureSuccessStatusCode to simplyfy debugging ESI #302

Open wvdvegt opened 2 years ago

wvdvegt commented 2 years ago

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();
            }
        }
dreamer2 commented 2 years ago

can you add all last changes to your fork?