ballerina-guides / gcp-microservices-demo

Ballerina Implementation of GCP Online Boutique Sample
Apache License 2.0
15 stars 38 forks source link

[Email Service]Improve the `SendOrderConfirmation` logic #70

Closed anupama-pathirage closed 1 year ago

anupama-pathirage commented 1 year ago

Description: Can we do the following log lines?

https://github.com/ballerina-guides/gcp-microservices-demo/blob/main/email/email_service.bal#L73:L74

Also we better handle the error first and then the success scenario.

Current code:

        gmail:Message|error sendMessageResponse = self.gmailClient->sendMessage(messageRequest);

        if sendMessageResponse is gmail:Message {
            log:printInfo(string `Sent Message ID: ${sendMessageResponse.id}`);
            log:printInfo(string `Sent Thread ID: ${sendMessageResponse.threadId}`);
            return {};
        }
        log:printError("Error sending confirmation mail ", sendMessageResponse);
        return sendMessageResponse;

Suggestion:

        gmail:Message|error sendMessageResponse = self.gmailClient->sendMessage(messageRequest);
        if sendMessageResponse is error {
            log:printError("Error in sending confirmation mail, ", sendMessageResponse);
            return sendMessageResponse;
        }
        log:printInfo(string `Email sent with Message ID: ${sendMessageResponse.id} and Thread ID: ${sendMessageResponse.threadId}`);
        return {};