I have being using Promises for a long time, and they are always the "thing" that I use to control the workflow of my programs. Example:
Promise
.resolve(obj)
.then(doSomething1)
.then(doSomething2)
.catch(handleError)
And now, I would like to change to a try-catch style, but I don't know exactly what would be the right approach.
V1:
try {
var body = await Promise
.resolve(obj)
.then(doSomething1)
.then(doSomething2)
} catch (error) {
callback(error)
}
callback(null, {
statusCode: 200,
body
})
V2:
try {
var body = await Promise
.resolve(obj)
.then(doSomething1)
.then(doSomething2)
.then(body => {
callback(null, {
statusCode: 200,
body
})
})
} catch (error) {
callback(error)
}
What would be the right approach?