-
-
Notifications
You must be signed in to change notification settings - Fork 930
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ids for user-facing errors for login, registration, settings
This patch adds a new field `id` to JSON error payloads. This helps tremendously in implementing better client-side (native / SPA) apps as the API now returns error IDs like `no_active_session`, `orbidden_return_to`, `no_verified_address` and more. UIs can use these IDs to decide what to do next in the application - for example redirecting to a particular endpoint or showing an error message.
- Loading branch information
Showing
15 changed files
with
227 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,53 @@ | ||
package flow | ||
|
||
import ( | ||
"github.com/ory/kratos/x" | ||
"time" | ||
|
||
"github.com/gofrs/uuid" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/ory/herodot" | ||
"github.com/ory/kratos/text" | ||
) | ||
|
||
var ( | ||
ErrStrategyNotResponsible = errors.New("strategy is not responsible for this request") | ||
ErrCompletedByStrategy = errors.New("flow response completed by strategy") | ||
ErrStrategyAsksToReturnToUI = errors.New("flow strategy is redirecting to the ui") | ||
) | ||
|
||
// Is sent when a flow is expired | ||
// | ||
// swagger:model selfServiceFlowExpiredError | ||
type ExpiredError struct { | ||
*herodot.DefaultError | ||
|
||
// Since when the flow has expired | ||
Ago time.Duration `json:"since"` | ||
|
||
// The flow ID that should be used for the new flow as it contains the correct messages. | ||
FlowID uuid.UUID `json:"use_flow_id"` | ||
|
||
flow Flow | ||
} | ||
|
||
func (e *ExpiredError) WithFlow(flow Flow) *ExpiredError { | ||
e.FlowID = flow.GetID() | ||
e.flow = flow | ||
return e | ||
} | ||
|
||
func (e *ExpiredError) GetFlow() Flow { | ||
return e.flow | ||
} | ||
|
||
func NewFlowExpiredError(at time.Time) *ExpiredError { | ||
ago := time.Since(at) | ||
return &ExpiredError{ | ||
Ago: ago, | ||
DefaultError: x.ErrGone.WithID(text.ErrIDSelfServiceFlowExpired). | ||
WithError("self-service flow expired"). | ||
WithReasonf("The self-service flow expired %.2f minutes ago, initialize a new one.", ago.Minutes()), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,5 @@ type Flow interface { | |
GetID() uuid.UUID | ||
GetType() Type | ||
GetRequestURL() string | ||
AppendTo(*url.URL) *url.URL | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.