Qiniu.Http.HttpCode.GetErrorMessage C# (CSharp) Méthode

GetErrorMessage() public static méthode

public static GetErrorMessage ( int code, string &errorMsg ) : bool
code int
errorMsg string
Résultat bool
        public static bool GetErrorMessage(int code,out string errorMsg)
        {
            bool isOtherCode = false;

            switch (code)
            {
                case (int)HCODE.PART_OK:
                case (int)HCODE.REQUEST_ERR:
                case (int)HCODE.AUTHENTICATION_ERR:
                case (int)HCODE.ACCESS_DENIED:
                case (int)HCODE.OBJECT_NOT_FOUND:
                case (int)HCODE.BAD_REQUEST:
                case (int)HCODE.CRC32_CHECk_ERR:
                case (int)HCODE.FSIZE_LIMIT_EXCEED:
                case (int)HCODE.ACCOUNT_BLOCKED:
                case (int)HCODE.MIRR2ORG_ERR:
                case (int)HCODE.BAD_GATEWAY:
                case (int)HCODE.SERVICE_UNAVAILABLE:
                case (int)HCODE.SERVER_TIMEOUT:
                case (int)HCODE.TOO_FREQUENT:
                case (int)HCODE.CALLBACK_FAILED:
                case (int)HCODE.SERVER_SIDE_FAILURE:
                case (int)HCODE.CONTENT_MODIFIED:
                case (int)HCODE.RESOURCE_NOT_EXSISTS:
                case (int)HCODE.RESOURCE_ALREADY_EXISTS:
                case (int)HCODE.NUM_OF_BUCKETS_EXCEEDS:
                case (int)HCODE.BUCKET_NOT_EXSISTS:
                case (int)HCODE.INVALID_LIST_MARKER:
                case (int)HCODE.RESUMABLE_UPLOAD_ERR:
                    errorMsg = HttpCode.GetMessage(code);
                    break;
                default:
                    errorMsg = "";
                    isOtherCode = true;
                    break;
            }

            return isOtherCode;
        }

Usage Example

Exemple #1
0
        private void handleWebResponse(HttpWebResponse pWebResp, CompletionHandler pCompletionHandler)
        {
            DateTime startTime = DateTime.Now;
            //check for exception
            int    statusCode = ResponseInfo.NetworkError;
            string reqId      = null;
            string xlog       = null;
            string ip         = null;
            string xvia       = null;
            string error      = null;
            string host       = null;
            string respData   = null;

            statusCode = (int)pWebResp.StatusCode;
            if (pWebResp.Headers != null)
            {
                WebHeaderCollection respHeaders = pWebResp.Headers;
                foreach (string headerName in respHeaders.AllKeys)
                {
                    if (headerName.Equals("X-Reqid"))
                    {
                        reqId = respHeaders[headerName].ToString();
                    }
                    else if (headerName.Equals("X-Log"))
                    {
                        xlog = respHeaders[headerName].ToString();
                    }
                    else if (headerName.Equals("X-Via"))
                    {
                        xvia = respHeaders[headerName].ToString();
                    }
                    else if (headerName.Equals("X-Px"))
                    {
                        xvia = respHeaders[headerName].ToString();
                    }
                    else if (headerName.Equals("Fw-Via"))
                    {
                        xvia = respHeaders[headerName].ToString();
                    }
                    else if (headerName.Equals("Host"))
                    {
                        host = respHeaders[headerName].ToString();
                    }
                }

                using (StreamReader respStream = new StreamReader(pWebResp.GetResponseStream()))
                {
                    respData = respStream.ReadToEnd();
                }

                try
                {
                    /////////////////////////////////////////////////////////////
                    // 改进Response的error解析, 根据HttpStatusCode
                    // @fengyh 2016-08-17 18:29
                    /////////////////////////////////////////////////////////////
                    if (statusCode != (int)HCODE.OK)
                    {
                        bool isOtherCode = HttpCode.GetErrorMessage(statusCode, out error);

                        if (isOtherCode)
                        {
                            Dictionary <string, string> errorDict = JsonConvert.DeserializeObject <Dictionary <string, string> >(respData);
                            error = errorDict["error"];
                        }
                    }
                }
                catch (Exception) { }
            }

            double       duration = DateTime.Now.Subtract(startTime).TotalSeconds;
            ResponseInfo respInfo = new ResponseInfo(statusCode, reqId, xlog, xvia, host, ip, duration, error);

            if (pCompletionHandler != null)
            {
                pCompletionHandler(respInfo, respData);
            }
        }
All Usage Examples Of Qiniu.Http.HttpCode::GetErrorMessage