diff --git a/selfservice/flow/login/error.go b/selfservice/flow/login/error.go index e4ce68c8b1a2..e7da5da2ca81 100644 --- a/selfservice/flow/login/error.go +++ b/selfservice/flow/login/error.go @@ -81,11 +81,8 @@ func (s *ErrorHandler) PrepareReplacementForExpiredFlow(w http.ResponseWriter, r func (s *ErrorHandler) WriteFlowError(w http.ResponseWriter, r *http.Request, f *Flow, group node.UiNodeGroup, err error) { logger := s.d.Audit(). WithError(err). - WithRequest(r) - - if f != nil { - logger = logger.WithField("login_flow", f.ToLoggerField()) - } + WithRequest(r). + WithField("login_flow", f.ToLoggerField()) logger. Info("Encountered self-service login error.") diff --git a/selfservice/flow/login/flow.go b/selfservice/flow/login/flow.go index 86232ebd25f1..806ba67a93eb 100644 --- a/selfservice/flow/login/flow.go +++ b/selfservice/flow/login/flow.go @@ -328,7 +328,10 @@ func (f *Flow) SetReturnToVerification(to string) { f.ReturnToVerification = to } -func (f Flow) ToLoggerField() map[string]interface{} { +func (f *Flow) ToLoggerField() map[string]interface{} { + if f == nil { + return map[string]interface{}{} + } return map[string]interface{}{ "id": f.ID.String(), "return_to": f.ReturnTo, diff --git a/selfservice/flow/recovery/error.go b/selfservice/flow/recovery/error.go index 7f4e335d441f..837bc6e0e4b3 100644 --- a/selfservice/flow/recovery/error.go +++ b/selfservice/flow/recovery/error.go @@ -66,10 +66,9 @@ func (s *ErrorHandler) WriteFlowError( ) { logger := s.d.Audit(). WithError(recoveryErr). - WithRequest(r) - if f != nil { - logger = logger.WithField("recovery_flow", f.ToLoggerField()) - } + WithRequest(r). + WithField("recovery_flow", f.ToLoggerField()) + logger. Info("Encountered self-service recovery error.") diff --git a/selfservice/flow/recovery/flow.go b/selfservice/flow/recovery/flow.go index 0e1c40e16ae4..7dc1845a77b6 100644 --- a/selfservice/flow/recovery/flow.go +++ b/selfservice/flow/recovery/flow.go @@ -249,14 +249,17 @@ func (t *Flow) GetTransientPayload() json.RawMessage { return t.TransientPayload } -func (t Flow) ToLoggerField() map[string]interface{} { +func (f *Flow) ToLoggerField() map[string]interface{} { + if f == nil { + return map[string]interface{}{} + } return map[string]interface{}{ - "id": t.ID.String(), - "return_to": t.ReturnTo, - "request_url": t.RequestURL, - "active": t.Active, - "type": t.Type, - "nid": t.NID, - "state": t.State, + "id": f.ID.String(), + "return_to": f.ReturnTo, + "request_url": f.RequestURL, + "active": f.Active, + "type": f.Type, + "nid": f.NID, + "state": f.State, } } diff --git a/selfservice/flow/registration/error.go b/selfservice/flow/registration/error.go index 6cff3cd26f2b..41a15f08b2b1 100644 --- a/selfservice/flow/registration/error.go +++ b/selfservice/flow/registration/error.go @@ -86,10 +86,9 @@ func (s *ErrorHandler) WriteFlowError( logger := s.d.Audit(). WithError(err). - WithRequest(r) - if f != nil { - logger = logger.WithField("registration_flow", f.ToLoggerField()) - } + WithRequest(r). + WithField("registration_flow", f.ToLoggerField()) + logger. Info("Encountered self-service flow error.") diff --git a/selfservice/flow/registration/flow.go b/selfservice/flow/registration/flow.go index 2f37501c60c2..5b39dd76f750 100644 --- a/selfservice/flow/registration/flow.go +++ b/selfservice/flow/registration/flow.go @@ -280,7 +280,10 @@ func (f *Flow) SetReturnToVerification(to string) { f.ReturnToVerification = to } -func (f Flow) ToLoggerField() map[string]interface{} { +func (f *Flow) ToLoggerField() map[string]interface{} { + if f == nil { + return map[string]interface{}{} + } return map[string]interface{}{ "id": f.ID.String(), "return_to": f.ReturnTo, diff --git a/selfservice/flow/settings/error.go b/selfservice/flow/settings/error.go index b5f1f1b636db..aaf6076de0be 100644 --- a/selfservice/flow/settings/error.go +++ b/selfservice/flow/settings/error.go @@ -142,12 +142,9 @@ func (s *ErrorHandler) WriteFlowError( ) { logger := s.d.Audit(). WithError(err). - WithRequest(r) + WithRequest(r). + WithField("settings_flow", f.ToLoggerField()) - if f != nil { - logger = logger. - WithField("settings_flow", f.ToLoggerField()) - } logger.Info("Encountered self-service settings error.") shouldRespondWithJSON := x.IsJSONRequest(r) diff --git a/selfservice/flow/settings/flow.go b/selfservice/flow/settings/flow.go index e356499e83ae..b32b4676effb 100644 --- a/selfservice/flow/settings/flow.go +++ b/selfservice/flow/settings/flow.go @@ -267,6 +267,9 @@ func (t *Flow) GetTransientPayload() json.RawMessage { } func (f *Flow) ToLoggerField() map[string]interface{} { + if f == nil { + return map[string]interface{}{} + } return map[string]interface{}{ "id": f.ID.String(), "return_to": f.ReturnTo, diff --git a/selfservice/flow/verification/error.go b/selfservice/flow/verification/error.go index 018a9e046c89..0fcffe84869e 100644 --- a/selfservice/flow/verification/error.go +++ b/selfservice/flow/verification/error.go @@ -62,11 +62,9 @@ func (s *ErrorHandler) WriteFlowError( ) { logger := s.d.Audit(). WithError(err). - WithRequest(r) + WithRequest(r). + WithField("verification_flow", f.ToLoggerField()) - if f != nil { - logger = logger.WithField("verification_flow", f.ToLoggerField()) - } logger. Info("Encountered self-service verification error.") diff --git a/selfservice/flow/verification/flow.go b/selfservice/flow/verification/flow.go index 4975f63a433c..ca78688fc441 100644 --- a/selfservice/flow/verification/flow.go +++ b/selfservice/flow/verification/flow.go @@ -298,7 +298,10 @@ func (t *Flow) GetTransientPayload() json.RawMessage { return t.TransientPayload } -func (f Flow) ToLoggerField() map[string]interface{} { +func (f *Flow) ToLoggerField() map[string]interface{} { + if f == nil { + return map[string]interface{}{} + } return map[string]interface{}{ "id": f.ID.String(), "return_to": f.ReturnTo,