Exemple #1
0
 /// <summary>
 /// Initializes a new exception based on the specified <paramref name="response"/> and <paramref name="meta"/> data.
 /// </summary>
 /// <param name="response">The response the exception should be based on.</param>
 /// <param name="meta">The meta data with information about the exception.</param>
 public InstagramOAuthAccessTokenException(SocialHttpResponse response, InstagramMetaData meta) : base(response, meta)
 {
 }
 /// <summary>
 /// Initializes a new exception based on the specified <paramref name="response"/> and <paramref name="meta"/> data.
 /// </summary>
 /// <param name="response">The response the exception should be based on.</param>
 /// <param name="meta">The meta data with information about the exception.</param>
 public InstagramOAuthPermissionsException(SocialHttpResponse response, InstagramMetaData meta) : base(response, meta)
 {
 }
Exemple #3
0
 /// <summary>
 /// Initializes a new exception based on the specified <paramref name="response"/> and <paramref name="meta"/> data.
 /// </summary>
 /// <param name="response">The response the exception should be based on.</param>
 /// <param name="meta">The meta data with information about the exception.</param>
 public InstagramOAuthRateLimitException(SocialHttpResponse response, InstagramMetaData meta) : base(response, meta)
 {
 }
 internal InstagramHttpException(SocialHttpResponse response, InstagramMetaData meta) : base(meta.ErrorMessage)
 {
     Response     = response;
     RateLimiting = InstagramRateLimiting.GetFromResponse(response);
     Meta         = meta;
 }
        /// <summary>
        /// Validates the specified <paramref name="response"/>.
        /// </summary>
        /// <param name="response">The response to be validated.</param>
        public static void ValidateResponse(SocialHttpResponse response)
        {
            // Skip error checking if the server responds with an OK status code
            if (response.StatusCode == HttpStatusCode.OK)
            {
                return;
            }

            // Handle errors when the response body isn't JSON
            if (!response.Body.StartsWith("{"))
            {
                switch (response.StatusCode)
                {
                case HttpStatusCode.NotFound:
                    throw new InstagramNotFoundException(response);

                default:
                    throw new InstagramHttpException(response);
                }
            }

            // Parse the response body
            JObject obj = ParseJsonObject(response.Body);

            // Get the "meta" object (may be the root object for some errors)
            InstagramMetaData meta = obj.HasValue("code") ? InstagramMetaData.Parse(obj) : obj.GetObject("meta", InstagramMetaData.Parse);

            // If the type isn't provided (it really should), we just throw an exception of the base type
            if (String.IsNullOrWhiteSpace(meta.ErrorType))
            {
                throw new InstagramHttpException(response, meta);
            }

            // Handle OAuth exception types
            if (meta.ErrorType.StartsWith("OAuth"))
            {
                switch (meta.ErrorType)
                {
                case "OAuthAccessTokenException":
                    throw new InstagramOAuthAccessTokenException(response, meta);

                case "OAuthForbiddenException":
                    throw new InstagramOAuthForbiddenException(response, meta);

                case "OAuthParameterException":
                    throw new InstagramOAuthParameterException(response, meta);

                case "OAuthPermissionsException":
                    throw new InstagramOAuthPermissionsException(response, meta);

                case "OAuthRateLimitException":
                    throw new InstagramOAuthRateLimitException(response, meta);

                default:
                    throw new InstagramOAuthException(response, meta);
                }
            }

            // Handle other error types
            switch (meta.ErrorType)
            {
            case "APINotFoundError":
                throw new InstagramNotFoundException(response, meta);

            default:
                throw new InstagramHttpException(response, meta);
            }
        }
Exemple #6
0
 internal InstagramNotFoundException(SocialHttpResponse response, InstagramMetaData meta) : base(response, meta)
 {
 }
 /// <summary>
 /// Initializes a new exception based on the specified <paramref name="response"/> and <paramref name="meta"/> data.
 /// </summary>
 /// <param name="response">The response the exception should be based on.</param>
 /// <param name="meta">The meta data with information about the exception.</param>
 public InstagramOAuthForbiddenException(SocialHttpResponse response, InstagramMetaData meta) : base(response, meta)
 {
 }