diff --git a/lib/jira.js b/lib/jira.js index e919d9da..867deb61 100644 --- a/lib/jira.js +++ b/lib/jira.js @@ -668,7 +668,51 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor return; } - if (response.statusCode !== 200) { + if (response.statusCode / 100 | 0 != 2) { + callback(response.statusCode + ': Unable to connect to JIRA during request.'); + return; + } + + callback(null, response.body); + + }); + }; + + /** + * Deletes the remote links associated with the given issue. + * + * @param issueNumber - The internal id (not the issue key) of the issue + * @param globalId - The global id of the remote link + * @param callback + */ + this.deleteRemoteLink = function deleteRemoteLink(issueNumber, remoteLinkGID, callback) { + + var options = { + rejectUnauthorized: this.strictSSL, + uri: this.makeUri('/issue/' + issueNumber + '/remotelink'), + method: 'DELETE', + qs: {globalId: remoteLinkGID}, + json: true + }; + + this.doRequest(options, function(error, response) { + + if (error) { + callback(error, null); + return; + } + + if (response.statusCode === 404) { + callback('Cannot delete remote link. Invalid issue.'); + return; + } + + if (response.statusCode === 400) { + callback('Cannot create remote link. ' + response.body.errors.title); + return; + } + + if (response.statusCode / 100 | 0 != 2) { callback(response.statusCode + ': Unable to connect to JIRA during request.'); return; }