available-versions
available-versions copied to clipboard
Check if response is JSON
Before trying to serialize response from the server
function onNPMversions(err, response, body) {
if (err) {
console.error('ERROR when fetching info for package', name);
return deferred.reject(new Error(err.message));
}
var result = {};
try {
var info = JSON.parse(body);
first check the response. Sometimes the server on WIFI is not allowed to make requests, so it fails badly processing HTML page.
- need better response check
If response is not JSON, throw error: "expected JSON response but got HTML response from
host: 'n68.network-auth.com'and print contents of the response?