569532 (7) [Avatar] Offline
#1
What is the best way to handle errors using Yield.
If we're using a promise, we can handle the error, but using yield is a different story. I liked using yield so far as it keeps the code readable. So what I'm doing to handle errors is the following:

try {
        // Get queue name
        let urlRequest = yield sqs.getQueueUrl({ QueueName: webhooks_sqs }).promise();

        if (_.get(urlRequest, "QueueUrl", false) === false)
            throw new Error(`error retreiving queue URL: [${webhooks_sqs}]`);
        ......
} catch (e) {
         console.log(e.message);
}



Do you think this is the best way to do that?
Morgatz (8) [Avatar] Offline
#2
This is pretty much how you do it with async/await which I'd recommend using it over co, generator functions, and yield

async yourFunctionName() {
  try {
    // Get queue name
    let urlRequest = await sqs.getQueueUrl({ QueueName: webhooks_sqs }).promise();
    if (_.get(urlRequest, "QueueUrl", false) === false)
        throw new Error(`error retreiving queue URL: [${webhooks_sqs}]`);
    ......
  } catch (e) {
    console.log(e.message)
  }
}