예제 #1
0
        /// <summary>
        /// Depending on the http status code received, determine what is the expected type of the json string.
        /// </summary>
        /// <returns></returns>
        public object ApiResponseProcessor()
        {
            object o;

            try
            {
                // Check the status code
                switch (this.StatusCode)
                {
                case 200:
                    o = this.ApiResponseDispatcher();
                    break;

                case 400:
                case 401:
                case 403:
                case 404:
                    o = BaseError.FromJson(this.Json);
                    break;

                default:
                    // build a BaseError
                    o = new BaseError();
                    Error er = new Error();
                    er.Name              = "Unknown StatusCode";
                    er.Message           = "The status code returned is of an unknown type.";
                    ((BaseError)o).Error = er;
                    break;
                }
                //log.Info("ApiResponse statuscode [" + StatusCode + "] for uri [" + Uri + "]");
                return(o);
            }
            catch (Exception exc)
            {
                o = new BaseError();
                Error er = new Error();
                er.Name              = "ApiResponseError";
                er.Message           = exc.ToString();
                ((BaseError)o).Error = er;
                //log.Error("ApiResponse error [" + exc.ToString() + "]");
                return(o);
            }
        }