Skip to content

Commit

Permalink
fix: return the error code instead of status code (#1855)
Browse files Browse the repository at this point in the history
## What kind of change does this PR introduce?
* Return the error code for in the redirect URL instead of the status
code
  • Loading branch information
kangmingtay authored Dec 4, 2024
1 parent 1bad34e commit 834a380
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
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))
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

0 comments on commit 834a380

Please sign in to comment.