feat(op): allow returning of parent errors to client
This commit is contained in:
parent
b9bcd6aef9
commit
2cbf96e448
2 changed files with 63 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
package oidc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
@ -133,6 +134,24 @@ type Error struct {
|
|||
Description string `json:"error_description,omitempty" schema:"error_description,omitempty"`
|
||||
State string `json:"state,omitempty" schema:"state,omitempty"`
|
||||
redirectDisabled bool `schema:"-"`
|
||||
returnParent bool `schema:"-"`
|
||||
}
|
||||
|
||||
func (e *Error) MarshalJSON() ([]byte, error) {
|
||||
m := struct {
|
||||
Error errorType `json:"error"`
|
||||
ErrorDescription string `json:"error_description,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Parent string `json:"parent,omitempty"`
|
||||
}{
|
||||
Error: e.ErrorType,
|
||||
ErrorDescription: e.Description,
|
||||
State: e.State,
|
||||
}
|
||||
if e.returnParent {
|
||||
m.Parent = e.Parent.Error()
|
||||
}
|
||||
return json.Marshal(m)
|
||||
}
|
||||
|
||||
func (e *Error) Error() string {
|
||||
|
@ -165,6 +184,11 @@ func (e *Error) WithParent(err error) *Error {
|
|||
return e
|
||||
}
|
||||
|
||||
func (e *Error) WithReturnParentToClient(b bool) *Error {
|
||||
e.returnParent = b
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *Error) WithDescription(desc string, args ...any) *Error {
|
||||
e.Description = fmt.Sprintf(desc, args...)
|
||||
return e
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue