Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return the error code instead of status code #1855

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions internal/api/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"net/http"
"net/url"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -635,7 +634,7 @@ func getErrorQueryString(err error, errorID string, log logrus.FieldLogger, q ur
log.WithError(e.Cause()).Info(e.Error())
}
q.Set("error_description", e.Message)
q.Set("error_code", strconv.Itoa(e.HTTPStatus))
kangmingtay marked this conversation as resolved.
Show resolved Hide resolved
q.Set("error_code", e.ErrorCode)
case *OAuthError:
q.Set("error", e.Err)
q.Set("error_description", e.Description)
Expand Down
4 changes: 2 additions & 2 deletions internal/api/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,10 @@ func (a *API) prepErrorRedirectURL(err *HTTPError, r *http.Request, rurl string,
hq.Set("error", str)
q.Set("error", str)
}
hq.Set("error_code", strconv.Itoa(err.HTTPStatus))
hq.Set("error_code", err.ErrorCode)
hq.Set("error_description", err.Message)

q.Set("error_code", strconv.Itoa(err.HTTPStatus))
q.Set("error_code", err.ErrorCode)
q.Set("error_description", err.Message)
if flowType == models.PKCEFlow {
// Additionally, may override existing error query param if set to PKCE.
Expand Down
6 changes: 3 additions & 3 deletions internal/api/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func (ts *VerifyTestSuite) TestExpiredConfirmationToken() {

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

f, err := url.ParseQuery(rurl.Fragment)
require.NoError(ts.T(), err)
assert.Equal(ts.T(), "403", f.Get("error_code"))
assert.Equal(ts.T(), ErrorCodeUserBanned, f.Get("error_code"))
})
}
}
Expand Down Expand Up @@ -1145,7 +1145,7 @@ func (ts *VerifyTestSuite) TestPrepRedirectURL() {

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

cases := []struct {
desc string
Expand Down
Loading