コード例 #1
0
        public BaseControllerResponseModel <T> CheckResponse <T>(HttpResponseMessage data)
        {
            ErrorViewModel errorViewModel = new ErrorViewModel();

            try
            {
                if (data.IsSuccessStatusCode)
                {
                    var               responseContent = data.Content;
                    string            responseString  = responseContent.ReadAsStringAsync().Result;
                    BaseResponseModel result          = JsonConvert.DeserializeObject <BaseResponseModel>(responseString);
                    if (result.responseMessageModel.isSuccess)
                    {
                        var successResponse = JsonConvert.DeserializeObject <SuccessResponseModel <T> >(responseString);
                        return(new BaseControllerResponseModel <T>(successResponse.responseObj));
                    }
                    else
                    {
                        errorViewModel = new ErrorViewModel(500, description: result.responseMessageModel.message);
                        //ErrorViewModel.GetServerError;
                    }
                }
                else
                {
                    errorViewModel = new ErrorViewModel((int)data.StatusCode, data.StatusCode.ToString());
                }
            }
            catch (Exception ex)
            {
                errorViewModel = ErrorViewModel.GetClientError(ex.Message.ToString());
            }
            return(new BaseControllerResponseModel <T>(errorViewModel));
        }