Ejemplo n.º 1
0
        /// <summary>
        /// Will attempt to wrap the exception, returning true if the exception was wrapped, or returning false if it was not (in which case
        /// the original exception should be thrown).
        /// </summary>
        /// <param name="requestContext"></param>
        /// <param name="webEx"></param>
        /// <param name="authException"></param>
        /// <param name="responseBodyAction"></param>
        /// <returns></returns>
        public static bool TryWrapException(IOAuthContext requestContext, WebException webEx, out OAuthException authException, Action <string> responseBodyAction)
        {
            try
            {
                string content = webEx.Response.ReadToEnd();

                if (responseBodyAction != null)
                {
                    responseBodyAction(content);
                }

                if (content.Contains(Parameters.OAuth_Problem))
                {
                    var report = new OAuthProblemReport(content);
                    authException = new OAuthException(report.ProblemAdvice ?? report.Problem, webEx)
                    {
                        Context = requestContext, Report = report
                    };
                    return(true);
                }
            }
            catch
            {
            }
            authException = new OAuthException();
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Missing Required OAuth Parameter
        /// </summary>
        /// <param name="context">The OAuth context.</param>
        /// <param name="parameterName">The parameter name.</param>
        /// <returns>The exception.</returns>
        public static OAuthException MissingRequiredOAuthParameter(IOAuthContext context, string parameterName)
        {
            var exception = new OAuthException(context, OAuthProblemParameters.ParameterAbsent,
                                               string.Format("Missing required parameter : {0}", parameterName));

            exception.Report.ParametersAbsent.Add(parameterName);
            return(exception);
        }