Skip to content

Commit

Permalink
chore: extract error to variable
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik committed Aug 9, 2024
1 parent 01020f1 commit b3ec44c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion persistence/sql/identity/persister_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ func (p *IdentityPersister) ListIdentities(ctx context.Context, params identity.
defer otelx.End(span, &err)

if _, err := uuid.FromString(paginator.Token().Encode()); err != nil {
return nil, nil, errors.WithStack(herodot.ErrBadRequest.WithReason("The page token is invalid, do not craft your own page tokens"))
return nil, nil, errors.WithStack(x.PageTokenInvalid)
}

nid := p.NetworkID(ctx)
Expand Down
3 changes: 2 additions & 1 deletion persistence/sql/persister_courier.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/ory/kratos/courier"
"github.com/ory/kratos/persistence/sql/update"
"github.com/ory/kratos/x"
)

var _ courier.Persister = new(Persister)
Expand Down Expand Up @@ -58,7 +59,7 @@ func (p *Persister) ListMessages(ctx context.Context, filter courier.ListCourier
paginator := keysetpagination.GetPaginator(opts...)

if _, err := uuid.FromString(paginator.Token().Encode()); err != nil {
return nil, 0, nil, errors.WithStack(herodot.ErrBadRequest.WithReason("The page token is invalid, do not craft your own page tokens"))
return nil, 0, nil, errors.WithStack(x.PageTokenInvalid)
}

messages := make([]courier.Message, paginator.Size())
Expand Down
3 changes: 2 additions & 1 deletion persistence/sql/persister_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/ory/kratos/identity"
"github.com/ory/kratos/session"
"github.com/ory/kratos/x"
"github.com/ory/kratos/x/events"
"github.com/ory/x/otelx"
"github.com/ory/x/pagination/keysetpagination"
Expand Down Expand Up @@ -83,7 +84,7 @@ func (p *Persister) ListSessions(ctx context.Context, active *bool, paginatorOpt
paginator := keysetpagination.GetPaginator(paginatorOpts...)

if _, err := uuid.FromString(paginator.Token().Encode()); err != nil {
return nil, 0, nil, errors.WithStack(herodot.ErrBadRequest.WithReason("The page token is invalid, do not craft your own page tokens"))
return nil, 0, nil, errors.WithStack(x.PageTokenInvalid)
}

if err := p.Transaction(ctx, func(ctx context.Context, c *pop.Connection) error {
Expand Down
15 changes: 9 additions & 6 deletions x/err.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ import (
"github.com/ory/herodot"
)

var PseudoPanic = herodot.DefaultError{
StatusField: http.StatusText(http.StatusInternalServerError),
ErrorField: "Code Bug Detected",
ReasonField: "The code ended up at a place where it should not have. Please report this as an issue at https://github.com/ory/kratos",
CodeField: http.StatusInternalServerError,
}
var (
PseudoPanic = herodot.DefaultError{
StatusField: http.StatusText(http.StatusInternalServerError),
ErrorField: "Code Bug Detected",
ReasonField: "The code ended up at a place where it should not have. Please report this as an issue at https://github.com/ory/kratos",
CodeField: http.StatusInternalServerError,
}
PageTokenInvalid = herodot.ErrBadRequest.WithReason("The page token is invalid, do not craft your own page tokens")
)

func RecoverStatusCode(err error, fallback int) int {
var sc herodot.StatusCodeCarrier
Expand Down

0 comments on commit b3ec44c

Please sign in to comment.