Skip to content

Commit

Permalink
fix: accept all 200 responses as OK in courier (#3401)
Browse files Browse the repository at this point in the history
* fix: accept all 200 responses as OK in courier

Closes #3399

* chore: synchronize workspaces
  • Loading branch information
aeneasr authored Aug 1, 2023
1 parent 4eaf6c8 commit 88237e2
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions courier/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"encoding/json"
"fmt"
"net/http"

"github.com/ory/kratos/request"
"github.com/ory/x/otelx"
Expand Down Expand Up @@ -64,30 +63,26 @@ func (c *courier) dispatchMailerEmail(ctx context.Context, msg Message) (err err

defer res.Body.Close()

switch res.StatusCode {
case http.StatusOK:
case http.StatusCreated:
default:
err = fmt.Errorf(
"unable to dispatch mail delivery because upstream server replied with status code %d",
res.StatusCode,
)
if res.StatusCode >= 200 && res.StatusCode < 300 {
c.deps.Logger().
WithField("message_id", msg.ID).
WithField("message_type", msg.Type).
WithField("message_template_type", msg.TemplateType).
WithField("message_subject", msg.Subject).
WithError(err).
Error("sending mail via HTTP failed.")
return err
Debug("Courier sent out mailer.")
return nil
}

err = fmt.Errorf(
"unable to dispatch mail delivery because upstream server replied with status code %d",
res.StatusCode,
)
c.deps.Logger().
WithField("message_id", msg.ID).
WithField("message_type", msg.Type).
WithField("message_template_type", msg.TemplateType).
WithField("message_subject", msg.Subject).
Debug("Courier sent out mailer.")

return nil
WithError(err).
Error("sending mail via HTTP failed.")
return err
}

0 comments on commit 88237e2

Please sign in to comment.