Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: accept all 200 responses as OK in courier #3401

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading