Example #1
0
        protected SteamResponse CreateErrorResponse( ISteamRequest request, Exception ex )
        {
            SteamResponse response = new SteamResponse();
            response.Request = request;
            response.IsSuccessful = false;
            response.ErrorMessage = ex.Message;

            if( ex is WebException ) {

                var webException = ex as WebException;
                if( webException != null ) {

                    if( webException.Status == WebExceptionStatus.RequestCanceled )
                        response.ResponseStatus = ResponseStatus.Aborted;
                    else
                        response.ResponseStatus = ResponseStatus.Error;

                    response.ErrorException = ex;

                    return response;
                }

            } else if( ex is TaskCanceledException ) {

                response.ErrorMessage = "The request timed out.";
                response.ResponseStatus = ResponseStatus.TimedOut;
                return response;

            }

            response.ErrorException = ex;
            response.ResponseStatus = ResponseStatus.Error;

            return response;
        }
Example #2
0
        protected SteamResponse ConvertToResponse( ISteamRequest request, HttpResponseMessage response, CookieContainer cookies )
        {
            var cookieJar = new Dictionary<string,Cookie>();

            if( cookies != null ) {
                foreach( Cookie cookie in cookies.GetCookies( response.RequestMessage.RequestUri ).Cast<Cookie>() ) {
                    cookieJar.Add( cookie.Name, cookie );
                }
            }

            SteamResponse steamResponse = new SteamResponse {
                HttpResponse = response,
                Request = request,
                RequestUri = response.RequestMessage.RequestUri,
                Cookies = cookieJar,
                ResponseStatus = SteamSharp.ResponseStatus.Completed,
                StatusCode = response.StatusCode,
                StatusDescription = response.StatusCode.ToString(),
                IsSuccessful = response.IsSuccessStatusCode
            };

            if( !steamResponse.IsSuccessful && response.ReasonPhrase != null )
                steamResponse.ErrorMessage = response.ReasonPhrase;

            StreamReader stream = new StreamReader( response.Content.ReadAsStreamAsync().Result, System.Text.Encoding.UTF8 );
            steamResponse.Content = stream.ReadToEnd();

            return steamResponse;
        }