You've already forked email-api-client
refactor: optimize file content encoding in NewAttachmentFromFileContent
All checks were successful
🚀 Publish Release Package / publish (push) Successful in 23s
All checks were successful
🚀 Publish Release Package / publish (push) Successful in 23s
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user