refactor: optimize file content encoding in NewAttachmentFromFileContent
All checks were successful
🚀 Publish Release Package / publish (push) Successful in 23s

This commit is contained in:
2025-06-25 16:42:34 -04:00
parent cf07508309
commit 8fb579805f

View File

@@ -3,6 +3,7 @@ package client
import (
"bytes"
"encoding/json"
"errors"
"net/http"
"time"
)
@@ -12,6 +13,11 @@ type EmailCreateResponse struct {
CreatedAt time.Time `json:"created_at"`
}
type ErrorResponse struct {
Message string `json:"message"`
Error string `json:"error"`
}
func (client *Client) SendEmail(request *EmailRequest) (*EmailCreateResponse, error) {
jsonData, _ := json.Marshal(request)
@@ -30,6 +36,15 @@ func (client *Client) SendEmail(request *EmailRequest) (*EmailCreateResponse, er
return nil, err
}
if resp.StatusCode != http.StatusOK {
response, err := readResponseBody[Response[ErrorResponse]](resp)
if err != nil {
return nil, err
}
return nil, errors.New(response.Payload.Message)
}
response, err := readResponseBody[Response[EmailCreateResponse]](resp)
if err != nil {
return nil, err