Skip to content

Error handling for SesTemplateController #13

@fayez-nazzal

Description

@fayez-nazzal

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions