Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if response is JSON #27

Open
bahmutov opened this issue Sep 10, 2017 · 0 comments
Open

Check if response is JSON #27

bahmutov opened this issue Sep 10, 2017 · 0 comments

Comments

@bahmutov
Copy link
Owner

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?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant