available-versions icon indicating copy to clipboard operation
available-versions copied to clipboard

Check if response is JSON

Open bahmutov opened this issue 8 years ago • 0 comments

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?

bahmutov avatar Sep 10 '17 20:09 bahmutov