Esempio n. 1
0
        /// <summary>
        /// Validates the specified <paramref name="response"/>.
        /// </summary>
        /// <param name="response">The response to be validated.</param>
        public static void ValidateResponse(IHttpResponse 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);

            if (response.ResponseUri.Host == "graph.facebook.com")
            {
                InstagramHttpError error = obj.GetObject("error", InstagramHttpError.Parse);
                throw new InstagramHttpException(response, error);
            }
        }
Esempio n. 2
0
 internal InstagramHttpException(IHttpResponse response, InstagramHttpError error) : base(error.Message)
 {
     Response     = response;
     RateLimiting = InstagramRateLimiting.GetFromResponse(response);
     Error        = error;
 }