示例#1
0
        private Exception parseException(WebException e)
        {
            var code = e.HttpStatusCode();
            var message = e.ResponseString();

            JToken json = null;
            try { json = JToken.Parse(message); }
            catch (Exception) { }

            if(json != null && json["error"] != null)
            {
                message = (string)json["error"]["message"] + " (" + (string)json["error"]["code"] + ")";
            }

            if (code == 401) return new AuthorizationFailureException(message, e);
            return e;
        }
示例#2
0
        private Exception parseException(WebException e)
        {
            string message = e.ResponseString();
            Nullable<int> code = e.HttpStatusCode();
            if (!string.IsNullOrEmpty(message)) message = (string)JObject.Parse(message)["error"];
            else message = string.Empty;
            if (code.HasValue) message += string.Format(" ({0})", code.Value);

            switch (code)
            {
                case 401:
                    // Unauthorized.
                    return new AuthorizationFailureException(message, e); 
                case 403:
                    // Forbidden.
                    return new FileConflictException(message, e);
                case 404:
                    // Not found.
                    return new FileNotFoundException(message, e);
                case 503: //TODO: implement delayed calling
                default:
                    if (code.HasValue && code / 100 == 5) return new ProviderNotAvailableException(message, e);
                    else return e;
            }
        }