Skip to content

Commit 834a380

Browse files
authored
fix: return the error code instead of status code (#1855)
## What kind of change does this PR introduce? * Return the error code for in the redirect URL instead of the status code
1 parent 1bad34e commit 834a380

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

internal/api/external.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"net/http"
77
"net/url"
8-
"strconv"
98
"strings"
109
"time"
1110

@@ -635,7 +634,7 @@ func getErrorQueryString(err error, errorID string, log logrus.FieldLogger, q ur
635634
log.WithError(e.Cause()).Info(e.Error())
636635
}
637636
q.Set("error_description", e.Message)
638-
q.Set("error_code", strconv.Itoa(e.HTTPStatus))
637+
q.Set("error_code", e.ErrorCode)
639638
case *OAuthError:
640639
q.Set("error", e.Err)
641640
q.Set("error_description", e.Description)

internal/api/verify.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,10 @@ func (a *API) prepErrorRedirectURL(err *HTTPError, r *http.Request, rurl string,
439439
hq.Set("error", str)
440440
q.Set("error", str)
441441
}
442-
hq.Set("error_code", strconv.Itoa(err.HTTPStatus))
442+
hq.Set("error_code", err.ErrorCode)
443443
hq.Set("error_description", err.Message)
444444

445-
q.Set("error_code", strconv.Itoa(err.HTTPStatus))
445+
q.Set("error_code", err.ErrorCode)
446446
q.Set("error_description", err.Message)
447447
if flowType == models.PKCEFlow {
448448
// Additionally, may override existing error query param if set to PKCE.

internal/api/verify_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func (ts *VerifyTestSuite) TestExpiredConfirmationToken() {
305305

306306
f, err := url.ParseQuery(rurl.Fragment)
307307
require.NoError(ts.T(), err)
308-
assert.Equal(ts.T(), "403", f.Get("error_code"))
308+
assert.Equal(ts.T(), ErrorCodeOTPExpired, f.Get("error_code"))
309309
assert.Equal(ts.T(), "Email link is invalid or has expired", f.Get("error_description"))
310310
assert.Equal(ts.T(), "access_denied", f.Get("error"))
311311
}
@@ -824,7 +824,7 @@ func (ts *VerifyTestSuite) TestVerifyBannedUser() {
824824

825825
f, err := url.ParseQuery(rurl.Fragment)
826826
require.NoError(ts.T(), err)
827-
assert.Equal(ts.T(), "403", f.Get("error_code"))
827+
assert.Equal(ts.T(), ErrorCodeUserBanned, f.Get("error_code"))
828828
})
829829
}
830830
}
@@ -1145,7 +1145,7 @@ func (ts *VerifyTestSuite) TestPrepRedirectURL() {
11451145

11461146
func (ts *VerifyTestSuite) TestPrepErrorRedirectURL() {
11471147
const DefaultError = "Invalid redirect URL"
1148-
redirectError := fmt.Sprintf("error=invalid_request&error_code=400&error_description=%s", url.QueryEscape(DefaultError))
1148+
redirectError := fmt.Sprintf("error=invalid_request&error_code=validation_failed&error_description=%s", url.QueryEscape(DefaultError))
11491149

11501150
cases := []struct {
11511151
desc string

0 commit comments

Comments
 (0)