Skip to content

Commit aa877b8

Browse files
committed
chore: add error messages
1 parent 89c9465 commit aa877b8

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

pkg/wrapper/kratos/login/login.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ func SubmitLoginFlowWrapper(cookie string, flowID string, csrfToken string, pass
4141
submitDataBody.UpdateLoginFlowWithPasswordMethod.SetCsrfToken(csrfToken)
4242

4343
apiClient := client.NewAPIClient(config.KratosClientConfig)
44-
4544
resp, r, err := apiClient.FrontendAPI.UpdateLoginFlow(context.Background()).Cookie(cookie).Flow(flowID).XSessionToken("").UpdateLoginFlowBody(submitDataBody).Execute()
4645

4746
responseCookies := r.Header["Set-Cookie"]
@@ -57,7 +56,7 @@ func SubmitLoginFlowWrapper(cookie string, flowID string, csrfToken string, pass
5756
return resp.Session, responseCookies[1], "", nil
5857
}
5958

60-
func SubmitLoginWithMFAWrapper(cookie string, flowID string, csrfToken string, totp string) (client.Session, string, error) {
59+
func SubmitLoginWithMFAWrapper(cookie string, flowID string, csrfToken string, totp string) (client.Session, string, string, error) {
6160
submitDataBody := client.UpdateLoginFlowBody{UpdateLoginFlowWithTotpMethod: client.NewUpdateLoginFlowWithTotpMethod("totp", totp)} // SubmitSelfServiceLoginFlowBody |
6261

6362
submitDataBody.UpdateLoginFlowWithTotpMethod.SetCsrfToken(csrfToken)
@@ -66,11 +65,13 @@ func SubmitLoginWithMFAWrapper(cookie string, flowID string, csrfToken string, t
6665

6766
resp, r, err := apiClient.FrontendAPI.UpdateLoginFlow(context.Background()).Flow(flowID).UpdateLoginFlowBody(submitDataBody).XSessionToken("").Cookie(cookie).Execute()
6867

68+
errMsg := helper.ExtractErrorMessage(r)
69+
6970
if err != nil {
70-
return *client.NewSessionWithDefaults(), "", err
71+
return *client.NewSessionWithDefaults(), "", errMsg, err
7172
}
7273

7374
responseCookies := r.Header["Set-Cookie"]
7475

75-
return resp.Session, responseCookies[0], nil
76+
return resp.Session, responseCookies[0], "", nil
7677
}

pkg/wrapper/kratos/recovery/recovery.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
client "github.com/ory/client-go"
99

1010
"github.com/sdslabs/nymeria/config"
11+
"github.com/sdslabs/nymeria/helper"
1112
)
1213

1314
func InitializeRecoveryFlowWrapper() (string, string, string, error) {
@@ -65,7 +66,7 @@ func SubmitRecoveryFlowWrapper(cookie string, flowID string, csrfToken string, e
6566
return csrf_token, nil
6667
}
6768

68-
func SubmitRecoveryCodeFlowWrapper(cookie string, flowID string, csrfToken string, recoveryCode string) (string, error) {
69+
func SubmitRecoveryCodeFlowWrapper(cookie string, flowID string, csrfToken string, recoveryCode string) (string, string, error) {
6970
submitFlowBody := client.UpdateRecoveryFlowBody{
7071
UpdateRecoveryFlowWithCodeMethod: client.NewUpdateRecoveryFlowWithCodeMethod("code"),
7172
}
@@ -78,10 +79,15 @@ func SubmitRecoveryCodeFlowWrapper(cookie string, flowID string, csrfToken strin
7879
if err != nil {
7980
fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.SubmitSelfServiceRecoveryFlow``: %v\n", err)
8081
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
81-
return "", err
82+
return "", "internal server error", err
8283
}
8384

8485
responseCookies := r.Header["Set-Cookie"]
8586

86-
return responseCookies[1], nil
87+
if len(responseCookies) < 2 {
88+
errMsg := helper.ExtractErrorMessage(r)
89+
return "", errMsg, nil
90+
}
91+
92+
return responseCookies[1], "", nil
8793
}

pkg/wrapper/kratos/settings/settings.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func SubmitSettingsFlowPasswordMethod(flow_cookie string, session_cookie string,
4545
msg := helper.ExtractErrorMessage(r)
4646
fmt.Fprintf(os.Stderr, "Error when calling `SubmitSettingsFlowPasswordMethod`: %v\n", err)
4747
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
48+
fmt.Fprintf(os.Stderr, "Error Message: %v\n", msg)
4849
return msg, err
4950
}
5051

@@ -100,5 +101,8 @@ func SubmitSettingsFlowTOTPMethod(flow_cookie string, session_cookie string, flo
100101

101102
msg := helper.ExtractSuccessMessage(r)
102103

103-
return msg + " Totp Toggled", nil
104+
if TOTPUnlink {
105+
return msg + " Totp Unlinked", nil
106+
}
107+
return msg + " Totp Linked", nil
104108
}

0 commit comments

Comments
 (0)