refactor: improve error handling for email sending failures
All checks were successful
🚀 Publish Release Package / publish (push) Successful in 23s

This commit is contained in:
2025-07-15 16:57:16 -04:00
parent 4fb41d15d7
commit af63421db1

View File

@@ -40,7 +40,14 @@ func (client *Client) SendEmail(request *EmailRequest) (*EmailCreateResponse, er
if resp.StatusCode >= http.StatusBadRequest {
response, err := readResponseBody[Response[ErrorResponse]](resp)
if err != nil {
return nil, err
bodyContents := make([]byte, resp.ContentLength)
_, err := resp.Body.Read(bodyContents)
if err != nil {
return nil, errors.New("Failed to read error response body: " + err.Error())
}
return nil, errors.New("An error occurred while sending the email: " + resp.Status + " - " + string(bodyContents))
}
if response.Payload.Message == "" {