Created
March 2, 2012 18:55
-
-
Save mrjcleaver/1960373 to your computer and use it in GitHub Desktop.
Why do I get ReferenceError: responseCallback is not defined at line 37:19?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
poster.freshBooksAPICall = function (parameters) { | |
var defaultCallback, responseCallBack, options, req; | |
defaultCallback = function (error, response, body) { | |
console.log('DEFAULT LOGGER =========================== ' + error + ' ' + response + ' ' + body); | |
}; | |
responseCallback = function responseCallback(error, response, bodyXML) { | |
// console.log("From Freshbooks API: ", error); | |
// console.log("Response Obj", response); | |
// console.log("BodyXML", bodyXML); | |
var responseTimeEntry, xmlObject, resultOkay, time_entry_id; | |
responseTimeEntry = new FreshBooks.TimeEntry(); // smell, why another? | |
xmlObject = jsdom.jsdom(bodyXML); | |
responseTimeEntry.loadXML(xmlObject); | |
resultOkay = responseTimeEntry.processResponse(xmlObject); | |
console.log("Freshbooks Response processed: ", resultOkay); | |
console.log("Freshbooks bodyXML: ", bodyXML); | |
if (resultOkay) { // it worked | |
// WORKAROUND FOR jsdom-should-extract-freshbooks-response var time_entry_id = responseTimeEntry.getXMLElementValue(xmlObject,'time_entry_id'); // | |
time_entry_id = xmlObject.getElementsByTagName("time_entry_id")[0].firstChild.nodeValue; | |
hook1.emit("Freshbooks ok", time_entry_id); | |
} else { | |
hook1.emit("Freshbooks rejected", responseTimeEntry.lastError); | |
} | |
console.log(result.statusCode); | |
}; | |
options = { | |
url: protocol + fbAuth + endpoint + fbPath, | |
method: parameters.method || "POST", | |
headers: { | |
contentType: "text/xml", | |
'Content-Length': parameters.data.length | |
}, | |
body: parameters.data || "", | |
onError: parameters.onError || defaultCallback('error') // smell, not sure it calls this. | |
}; | |
console.log(options); | |
req = request(options, responseCallback);// ('callback', error, response, body) | |
console.log("moving on"); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment