From af63421db1d12ebd863f36e33be203ce82215ba0 Mon Sep 17 00:00:00 2001 From: Ron Rise Date: Tue, 15 Jul 2025 16:57:16 -0400 Subject: [PATCH] refactor: improve error handling for email sending failures --- client/create.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client/create.go b/client/create.go index 06b90e7..e60d9fe 100755 --- a/client/create.go +++ b/client/create.go @@ -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 == "" {