airapi
airapi copied to clipboard
Better error handling
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));
}
});
@rogchap Thank you for pointing that out! I'll make the changes necessary. Keep 'em feedback coming! Much appreciated.
Si.