FAC10 / week5-jajascript

Never miss a train leaving from Bethnal Green again
https://week5-jajascript-bethnal-green.herokuapp.com/
5 stars 1 forks source link

tflAPI.js - Error Handling #55

Open njsfield opened 7 years ago

njsfield commented 7 years ago

You're coverage shows you are not testing the error branch when using the testRequest function

screen shot 2017-03-24 at 10 19 21

This error is returned but is not handled by the callback, therefore the function that calls this function with a callback will have no access to the error (in the error first manner). So this function call in the handler file

handler.serveTFL = function(req, res) { 
  tflAPI.testRequest(request, function (err, data) {    
    var timesObject = tflLogic.tflTest(err, data);
    res.writeHead(200, { 'Content-Type': 'application/json'});
    res.end(JSON.stringify(timesObject));   
  });   
}

will not deal with the error.

Perhaps return the error in the testRequest function, and in this handle function check for the error exists to serve notify the user in some way.

If you wanted to test the testRequest function, you'll never be certain that the tflApi url will not return data, but you can at least check the contents of the error branch is testRequest returns an error