コード例 #1
0
        private static Exception GetV2Exception(IDictionary<string, object> json, FluentHttpResponse response)
        {
            GithubApiException exception;
            if (json.ContainsKey("error"))
            {
                exception = new GithubApiException((string)json["error"]);
                return exception;
            }

            return new NotImplementedException();
        }
コード例 #2
0
        private object ProcessExchangeCodeForAccessTokenResponse(FluentHttpAsyncResult asyncResult, MemoryStream responseStream, out Exception exception)
        {
            // don't throw exception in this method but send it as an out parameter.
            // we can reuse this method for async methods too.
            // so the caller of this method decides whether to throw or not.
            exception = asyncResult.Exception;

            // FluentHttpRequest has ended.

            if (exception != null)
            {
                if (responseStream != null)
                    responseStream.Dispose();

                return null;
            }

            var response = asyncResult.Response;

            if (asyncResult.IsCancelled)
            {
                exception = new NotImplementedException();
                return null;
            }
            else
            {
                // async request completed
                // convert the response stream to string.
                responseStream.Seek(0, SeekOrigin.Begin);
                var responseString = FluentHttpRequest.ToString(responseStream);

                // we got the response string already, so dispose the memory stream.
                responseStream.Dispose();

                if (response.HttpWebResponse.StatusCode == HttpStatusCode.OK)
                {
                    var returnValue = GithubApi.ParseUrlQueryString(responseString);

                    if (returnValue.ContainsKey("error"))
                    {
                        // Github api responded with an error.
                        exception = new GithubApiException(returnValue["error"].ToString());
                        return null;
                    }
                    return returnValue;
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
        }