Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="httpResponse"></param>
        public AccountApiResponse(IHttpResponse httpResponse)
        {
            if (httpResponse != null)
            {
                this.RawResponse = httpResponse;
                this.Success     = httpResponse.Success;

                JObject jObject = this.TryGetResponseContentAsJson();
                if (jObject == null)
                {
                    if (httpResponse.Exception != null)
                    {
                        this.Error = AccountApiError.GetErrorFromException(httpResponse.Exception);
                    }
                    this.Success = false;
                }
                else if (!this.Success)
                {
                    this.Error = AccountApiError.GetErrorFromResponse(jObject);
                }
            }

            if ((!this.Success) && (this.Error != null))
            {
                throw new WebException(this.Error.Message);
            }
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="exception"></param>
        /// <returns></returns>
        public static AccountApiError GetErrorFromException(Exception exception)
        {
            AccountApiError accountApiError = new AccountApiError();

            accountApiError.Exception = exception;
            accountApiError.Message   = ProcessExceptionMessage(exception);
            return(accountApiError);
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="responseJson"></param>
        /// <returns></returns>
        public static AccountApiError GetErrorFromResponse(JObject responseJson)
        {
            AccountApiError accountApiError = new AccountApiError();
            JToken          jtokenCode      = responseJson.SelectToken("code");

            accountApiError.Code = (jtokenCode != null) ? jtokenCode.ToString() : null;
            JToken jtokenStatus = responseJson.SelectToken("status");

            accountApiError.Status = (jtokenStatus != null) ? jtokenStatus.ToString() : null;
            JToken jtokenMessage = responseJson.SelectToken("message");

            accountApiError.Message = (jtokenMessage != null) ? jtokenMessage.ToString() : null;
            JToken jtokenField = responseJson.SelectToken("field");

            accountApiError.Field = (jtokenField != null) ? jtokenField.ToString() : null;
            return(accountApiError);
        }