I am making http calls in meteor using the npm 'request' package.
I would like to know what type of error object is created when a response.statusCode is not equal to 200? Is this handled by the javascript engine and considered a runtime error?
Or if the statusCode is not equal to 200 is determined by the service provider whether they will create an error object or not?
If the latter, do I create a 'manual error', new Error('throwing my own error for the catch block to handle')
var request = function() {
// HTTP call to server
},
function (error, response, body) {
if (!error && response.statusCode === 200) {
// processed and created data object
return data
}
else {
return (error) ; // How can I ensure the catch(e) block in the try/catch method will catch the error with an addition of my own 'message'.
}
})
};
try {
request()
}
catch(e) {
console.log(e)
}
For my scenario, I would like to ensure the catch(e) block will grab this error and I would like to add my own message including the stack trace.
Aucun commentaire:
Enregistrer un commentaire