ocket8888 commented on a change in pull request #3534: TP Delivery Service 
Generate SSL update, new letsencrypt generate and…
URL: https://github.com/apache/trafficcontrol/pull/3534#discussion_r334605629
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/api/api.go
 ##########
 @@ -786,3 +792,81 @@ func AddUserToReq(r *http.Request, u auth.CurrentUser) {
        ctx = context.WithValue(ctx, auth.CurrentUserKey, u)
        *r = *r.WithContext(ctx)
 }
+
+func SendEmail(config config.Config, header string, data interface{}, 
templateFile string, toEmail string) error {
+       email := rfc.EmailAddress{
+               Address: mail.Address{Name: "", Address: toEmail},
+       }
+
+       msgBodyBuffer, err := parseTemplate(templateFile, data)
+       if err != nil {
+               return err
+       }
+       msg := append([]byte(header), msgBodyBuffer.Bytes()...)
+
+       int, userError, systemError := SendMail(email, msg, &config)
+       if userError != nil {
+               return errors.New("Failed to send email: " + userError.Error())
+       }
+       if systemError != nil {
+               return errors.New("Failed to send email: " + userError.Error())
 
 Review comment:
   So currently this returns `userError.Error()` even when `userError` was 
`nil`. That'll cause a segfault at runtime, but also it's returning the wrong 
error. Also, coalescing user errors and system errors is dangerous - you want 
to tell the user what they did wrong, but not expose the inner-workings of the 
server.
   
   I'd suggest you do one of two things:
   
   1. Return the semi-standard error code, user error and system error
   2. If there's some reason that the more general `SendMail` func isn't 
working for you, maybe try to modify it to suit your needs?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to