Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling for SesTemplateController #13

Open
fayez-nazzal opened this issue Sep 4, 2022 · 1 comment
Open

Error handling for SesTemplateController #13

fayez-nazzal opened this issue Sep 4, 2022 · 1 comment

Comments

@fayez-nazzal
Copy link

fayez-nazzal commented Sep 4, 2022

Manually creating promises for AWS SDK is not a good practice, and It does not throw all errors

Here is the recommended way for using promises ( And handling errors, too ), by the AWS SDK docs:
Using JS Promises with AWS SDK

Here is an example updating the createTemplate function:

From:

    await new Promise((resolve, reject) => {
      //do async AWS createTemplate
      ses.createTemplate(params, function (err, data) {
        if (err) {
          reject(err);
        } else {
          resolve(data);
        }
      });
    }).then(response.send(200, 'Created')).catch(err => {
      response.status(500);
      response.send(err);
    });

To:

    await new Promise((resolve, reject) => {
       try {
          ses.createTemplate(params).promise();
          response.status(200).send("Created");
        } catch (error) {
          response.status(500).send(error.message ?? "Error creating template");
       }
    });

===> This is the recommended way, and it is required for Unit testing of error handling, issue #4

@fayez-nazzal
Copy link
Author

@hammady

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant