示例#1
0
        public static void LogResponse(UnityWebRequest statusRequest)
        {
            long    code    = statusRequest.responseCode;
            LogType logType = statusRequest.IsOk()
                ? LogType.Log
                : LogType.Error;

            string format = "Response: {0} {1} {2} {3}";

            if (logger.IsLogTypeAllowed(logType))
            {
                // we split path like this to make sure api key doesn't leak
                Uri    uri  = new Uri(statusRequest.url);
                string path = string.Join("", uri.Segments);
                logger.LogFormat(logType, format, statusRequest.method, code, path, statusRequest.downloadHandler.text);
            }
        }
示例#2
0
        public IEnumerator SendRequestEnumerator(UnityWebRequest request, RequestSuccess onSuccess = null, RequestFail onFail = null)
        {
            using (UnityWebRequest webRequest = request) {
                yield return(webRequest.SendWebRequest());

                Logger.LogResponse(webRequest);

                string text = webRequest.downloadHandler.text;
                Logger.Verbose(text);
                if (webRequest.IsOk())
                {
                    onSuccess?.Invoke(text);
                }
                else
                {
                    onFail?.Invoke(text);
                }
            }
        }
示例#3
0
        public static void LogResponse(UnityWebRequest statusRequest)
        {
            long    code    = statusRequest.responseCode;
            LogType logType = statusRequest.IsOk()
                ? LogType.Log
                : LogType.Error;

            const string format = "Response: {0} {1} {2} {3}";

            if (logger.IsLogTypeAllowed(logType))
            {
                // we split path like this to make sure api key doesn't leak
                Uri    uri  = new Uri(statusRequest.url);
                string path = string.Join("", uri.Segments);
                string msg  = string.Format(format, statusRequest.method, code, path, statusRequest.downloadHandler.text);
                logger.Log(logType, msg);
            }

            if (!string.IsNullOrEmpty(statusRequest.error))
            {
                string msg = string.Format("WEB REQUEST ERROR: {0}", statusRequest.error);
                logger.Log(LogType.Error, msg);
            }
        }