public static GitHubFollowingResponse ParseResponse(SocialHttpResponse response) {

            switch (response.StatusCode) {

                case HttpStatusCode.NoContent:
                    return new GitHubFollowingResponse(response) {
                        IsFollowing = true
                    };

                case HttpStatusCode.NotFound:
                    return new GitHubFollowingResponse(response) {
                        IsFollowing = false
                    };

                default:

                    // Parse the raw JSON response
                    JsonObject obj = response.GetBodyAsJsonObject();

                    string message = obj.GetString("message");
                    string url = obj.GetString("documentation_url");
                    throw new GitHubHttpException(response, message, url);
                    
            }

        }
Exemplo n.º 2
0
        public static void ValidateResponse(SocialHttpResponse response) {

            // Skip error checking if the server responds with an OK status code
            if (response.StatusCode == HttpStatusCode.OK) return;

            // Get the "meta" object
            JsonObject obj = response.GetBodyAsJsonObject();

            // Now throw some exceptions
            string message = obj.GetString("message");
            string url = obj.GetString("documentation_url");
            throw new GitHubHttpException(response, message, url);

        }
Exemplo n.º 3
0
        /// <summary>
        /// Validates the specified <code>response</code>.
        /// </summary>
        /// <param name="response">The response to be validated.</param>
        public static void ValidateResponse(SocialHttpResponse response) {

            // The Slack API will always return a "200 OK" status even when an error is returned, so we need to check
            // the "ok" property in the boolean instead

            // Get root object
            JsonObject obj = response.GetBodyAsJsonObject();

            // Is the request/response successful?
            bool isOk = obj.GetBoolean("ok");
                
            // Now throw some exceptions
            if (!isOk) throw new SlackException(response, obj.GetString("error"));

        }
Exemplo n.º 4
0
        /// <summary>
        /// Validates the specified <code>response</code>.
        /// </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;

            // Get the "meta" object
            JsonObject obj = response.GetBodyAsJsonObject();

            // Now throw some exceptions
            throw new Exception("WTF?");
            //int code = obj.GetInt32("code");
            //string type = obj.GetString("error_type");
            //string message = obj.GetString("error_message") ?? obj.GetString("error");
            //throw new BasecampException(response, code, type, message);

        }
Exemplo n.º 5
0
        public static void ValidateResponse(SocialHttpResponse response) {

            // Skip error checking if the server responds with an OK status code
            if (response.StatusCode == HttpStatusCode.OK) return;

            JsonObject obj = response.GetBodyAsJsonObject();

            // For some types of errors, Twitter will only respond with an error message
            if (obj.HasValue("error")) {
                throw new TwitterException(response, obj.GetString("error"), 0);
            }

            // However in most cases, Twitter responds with an array of errors
            JsonArray errors = obj.GetArray("errors");

            // Get the first error (don't remember ever seeing multiple errors in the same response)
            JsonObject error = errors.GetObject(0);

            // Throw the exception
            throw new TwitterException(response, error.GetString("message"), error.GetInt32("code"));

        }