Skip to content

Better error handling #3

@rogchap

Description

@rogchap

request does not always have an err object when res.status !== 200

Using getInfo.js as an example:

request(requestConfigs, function(err, res, body) {
  if (!err && res.statusCode == 200) {
    resolve(JSON.parse(body));
  } else if (err) {
    reject(err);
  }
});

When calling this method with a listing ID that does not exist Airbnb return status = 404 with the body = {error_code:404, error: 'record_not_fond' ...} but err object in null.

Because of your "if else" statement neither resolve or reject is called... which is bad as this hangs and never returns.

Propose a change to something like:

request(requestConfigs, function(err, res, body) {
  if (res.statusCode == 200) {
    resolve(JSON.parse(body));
  } else {
    reject(JSON.parse(body));
  }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions