我该如何解决以下问题?

时间:2017-11-21 06:19:42

标签: node.js

我在代码中集成了JIRA REST API。在那里,一些响应对象显示为" Unauthorized",

{[  
{ "\n\n\n\n\n\n\n\n\n\n<html>\n\n<head>\n    <title>Unauthorized (401)</title>\n  },
{ "\n\n\n\n\n\n\n\n\n\n<html>\n\n<head>\n    <title>Unauthorized (401)</title>\n  },
{ "\n\n\n\n\n\n\n\n\n\n<html>\n\n<head>\n    <title>Unauthorized (401)</title>\n  },
{ \"errors\":[],\"detail\":[{\"repositories\":[],\"_instance\":{\"applicationLinkId\":\"4b0d5edc-c683-3502-aed7-5f6e152b877d\" },
{\"errors\":[],\"detail\":[{\"repositories\":[],\"_instance\":{\"applicationLinkId\":\"4b0d5edc-c683-3502-aed7-5f6e152b877d\"}
 ]}

我的实际代码是,

exports.getCommits = function(req, res) {
console.log(filename + '>>get commits>>');
var response = {
    status : Boolean,
    message : String,
    data : String
};
var request = require('request');
var username = username ;
var password = password ;
var options = {
    url : 'https://computenext.atlassian.net/rest/api/2/search?jql=status+%3D+Resolved+ORDER+BY+updated&maxResults=100',
    auth : {
        username : username,
        password : password
    }
};
request( options, function(error, obj) {
            if (error) {
                response.message = appmsg.DATA_NT_FOUND;
                response.status = false;
                response.data = obj;
                res.send(response);
            } else {
                 response.message = appmsg.DATA_FOUND;
                 response.status = true;
                 response.data = JSON.parse(obj.body);
                 var respon = {
                    status : Boolean,
                    message : String,
                    data : String
                };
                var issueKey = response.data.issues;
                var id = issueKey[0].id;
                 var commitout = [];
                 var lookup_list = [];
                 for(var i = 0; i < issueKey.length; i++) {
                     var commits = issueKey[i].id;
                     url = "https://computenext.atlassian.net/rest/dev-status/1.0/issue/detail?issueId=" + commits + "&applicationType=stash&dataType=repository";
                     auth = "Basic " + new Buffer(username + ":" + password ).toString("base64");
                  request({url : url, headers : {"Authorization" : auth}}, function(err, obj1){
                      if (obj1) {                            
                              commitout.push(obj1.body);
                              if(issueKey.length === commitout.length){
                                respon.message = appmsg.DATA_FOUND;
                                respon.status = true;
                                respon.data = commitout;        
                                res.send(respon);
                              }
                            }
                 });
                }
            }   
        });

};

请给我正确的解决方案。如何回复所有JIRA的提交?

  

有时它会正确显示所有细节但不是所有时间。我想对所有的点击做出适当的回应。

1 个答案:

答案 0 :(得分:0)

我认为&#34; OAuth&#34;这是必需的。现在我没有权限查看JIRA。所以,它只显示&#34; Unauthorized&#34;如上所述的错误。