Request Timeout

Hello

I am having some problem with api. I get this error : Request Timeout(4) When trying to follow a channel .
This is the code I use :

function follow3 (channelname){   
    var failure = function (error) {
        console.log("failure: " + error)
    };   
    Twitch.init({clientId: ''}, function(error, status) {
        Twitch.getStatus(function (error, status) {
            if (error) return failure(error.message + "(1)");
            if (!status.authenticated) return failure(error.message);         
            Twitch.api({method: 'user'}, function (error, user) {
                if (error) return failure(error.message + "(2)");
                var followed = false;
                if(followed) {
                    Twitch.api({verb: 'DELETE', method: 'users/' + user.name + '/follows/channels/' + channelname }, function (error, response) {
                        if (error) return failure(error.message + "(3)");
//                        return $scope.$apply($scope.followed = false);
                    });
                }
                else {
                    Twitch.api({verb: 'PUT', method: 'users/' + user.name + '/follows/channels/' + channelname }, function (error, response) {
                        if (error) return failure(error.message + "(4)");
//                        return $scope.$apply($scope.followed = true);
                    });
                }
            });
        });
    });
}

Is it timing out on the PUT or the DELETE? Are you using the JavaScript SDK? The SDK relies on the URL parameter, which has a known bug right now.

Hi !
Thanks for reply. it’s PUT method.

But i find a trick . I modified twitch.js like that :
var REQUEST_TIMEOUT = 5000; —> var REQUEST_TIMEOUT = 15000; // SO I have NO timeout

But twitch.api still make GET instead PUT so I change twitch.api like that :

Twitch.api = function (options, callback) {
...
$.ajax({
            url: url + '?' + $.param(params),
            dataType: 'json',  // I change jsonp to json (I don't know why but with jsonp it doesn't work)
            timeout: REQUEST_TIMEOUT,
            method: params._method  // I put there directly the method, this line doesn't exist in the origin file
        })
...

And now my follow button works like a charm. I don’t know if it’s the good way if someone have a better solution

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.