Closed alexpi closed 4 years ago
In the requestType function we have:
function requestType(name, handler) { defineRequestType(name, (nest, content, source, callback) => { try { Promise.resolve(handler(nest, content, source)) .then(response => callback(null, response), failure => callback(failure)); } catch (exception) { callback(exception); } }); }
The text states that the call to handler had to be wrapped in a try block to make sure any exception it raises directly is given to the callback.
Since Promise.resolve converts the value returned by handler to a Promise, shouldn't the second argument to then() catch all exceptions?
The call to handler() happens in the function itself, so when that throws, it'll raise a regular exception rather than creating a rejected promise.
handler()
In the requestType function we have:
The text states that the call to handler had to be wrapped in a try block to make sure any exception it raises directly is given to the callback.
Since Promise.resolve converts the value returned by handler to a Promise, shouldn't the second argument to then() catch all exceptions?