You've already forked email-api-client
refactor: improve error handling for email sending failures
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:
@@ -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 == "" {
|
||||
|
||||
Reference in New Issue
Block a user