JS Follow button API error

Thnx Fugiman!

for everyone else: if you’re looking for a follow button for your website. this should work for you keep in mind that this function uses some angular, can be easily replaced with other JS)

$scope.follow = function() {
        var failure = function (error) {
            console.log("failure: " + error)
        };

        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)");

                if($scope.followed) {

                    Twitch.api({verb: 'DELETE', method: 'users/' + user.name + '/follows/channels/' + channel }, 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/' + channel }, function (error, response) {
                        if (error) return failure(error.message + "(4)");
                        return $scope.$apply($scope.followed = true);
                    });
                }
            });
        });