public MixpanelHttpApiErrorException(ApiCallResult result, string message, Exception innerException)
     : base(message, innerException)
 {
     this.Result = result;
 }
Exemplo n.º 2
0
        protected virtual ApiCallResult HandleResponse(HttpWebRequest request, IAsyncResult result = null)
        {
            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);

            using (Stream stream = response.GetResponseStream())
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    String content = reader.ReadToEnd();
                    if (String.IsNullOrWhiteSpace(content))
                    {
                        throw new MixpanelHttpApiErrorException("No result returned");
                    }
                    else if (content == "1")
                    {
                        // we're good
                        return(new ApiCallResult()
                        {
                            Status = 1, IsSuccess = true, RawResult = content
                        });
                    }
                    else if (content == "0")
                    {
                        throw new MixpanelHttpApiErrorException(new ApiCallResult()
                        {
                            Status = 0, IsSuccess = false, RawResult = content
                        }, "Error returned from MixPanel without details");
                    }
                    else
                    {
                        ApiCallResult callResult = null;
                        try
                        {
                            callResult = JsonConvert.DeserializeObject <ApiCallResult>(content);
                        }
                        catch (Exception e)
                        {
                        }
                        if (callResult == null)
                        {
                            return(new ApiCallResult()
                            {
                                Status = 0, IsSuccess = false, RawResult = content
                            });
                        }
                        else if (callResult.Status == 1)
                        {
                            callResult.IsSuccess = true;
                            callResult.RawResult = content;
                            return(callResult);
                        }
                        else
                        {
                            callResult.IsSuccess = false;
                            callResult.RawResult = content;
                            throw new MixpanelHttpApiErrorException(callResult, "Error returned from MixPanel");
                        }
                    }
                }
            }
        }
 public MixpanelHttpApiErrorException(ApiCallResult result)
     : base()
 {
     this.Result = result;
 }