@@ -53,7 +53,7 @@ func (c *RefreshTokenGrantHandler) HandleTokenEndpointRequest(ctx context.Contex
53
53
54
54
return errorsx .WithStack (fosite .ErrInactiveToken .WithWrap (err ).WithDebug (err .Error ()))
55
55
} else if errors .Is (err , fosite .ErrNotFound ) {
56
- return errorsx .WithStack (fosite .ErrInvalidGrant .WithWrap (err ).WithDebugf ("The refresh token has not been found: %s" , err . Error () ))
56
+ return errorsx .WithStack (fosite .ErrInactiveToken .WithWrap (err ).WithDebug ("The refresh token can not be found." ))
57
57
} else if err != nil {
58
58
return errorsx .WithStack (fosite .ErrServerError .WithWrap (err ).WithDebug (err .Error ()))
59
59
} else if err := c .RefreshTokenStrategy .ValidateRefreshToken (ctx , originalRequest , refresh ); err != nil {
@@ -129,23 +129,20 @@ func (c *RefreshTokenGrantHandler) PopulateTokenEndpointResponse(ctx context.Con
129
129
if err != nil {
130
130
return errorsx .WithStack (fosite .ErrServerError .WithWrap (err ).WithDebug (err .Error ()))
131
131
}
132
- defer func () {
133
- err = c .handleRefreshTokenEndpointStorageError (ctx , err )
134
- }()
135
132
136
133
storeReq := requester .Sanitize ([]string {})
137
134
storeReq .SetID (requester .GetID ())
138
135
139
136
if err = c .TokenRevocationStorage .RotateRefreshToken (ctx , requester .GetID (), signature ); err != nil {
140
- return err
137
+ return c . handleRefreshTokenEndpointStorageError ( ctx , err )
141
138
}
142
139
143
140
if err = c .TokenRevocationStorage .CreateAccessTokenSession (ctx , accessSignature , storeReq ); err != nil {
144
- return err
141
+ return c . handleRefreshTokenEndpointStorageError ( ctx , err )
145
142
}
146
143
147
144
if err = c .TokenRevocationStorage .CreateRefreshTokenSession (ctx , refreshSignature , accessSignature , storeReq ); err != nil {
148
- return err
145
+ return c . handleRefreshTokenEndpointStorageError ( ctx , err )
149
146
}
150
147
151
148
responder .SetAccessToken (accessToken )
@@ -156,7 +153,7 @@ func (c *RefreshTokenGrantHandler) PopulateTokenEndpointResponse(ctx context.Con
156
153
responder .SetExtra ("refresh_token" , refreshToken )
157
154
158
155
if err = storage .MaybeCommitTx (ctx , c .TokenRevocationStorage ); err != nil {
159
- return err
156
+ return c . handleRefreshTokenEndpointStorageError ( ctx , err )
160
157
}
161
158
162
159
return nil
@@ -214,14 +211,14 @@ func (c *RefreshTokenGrantHandler) handleRefreshTokenEndpointStorageError(ctx co
214
211
return errorsx .WithStack (fosite .ErrInvalidRequest .
215
212
WithDebugf (storageErr .Error ()).
216
213
WithWrap (storageErr ).
217
- WithHint ("Failed to refresh token because of multiple concurrent requests using the same token which is not allowed ." ))
214
+ WithHint ("Failed to refresh token because of multiple concurrent requests using the same token. Please retry the request ." ))
218
215
}
219
216
220
217
if errors .Is (storageErr , fosite .ErrNotFound ) || errors .Is (storageErr , fosite .ErrInactiveToken ) {
221
218
return errorsx .WithStack (fosite .ErrInvalidRequest .
222
219
WithDebugf (storageErr .Error ()).
223
220
WithWrap (storageErr ).
224
- WithHint ("Failed to refresh token because of multiple concurrent requests using the same token which is not allowed ." ))
221
+ WithHint ("Failed to refresh token. Please retry the request ." ))
225
222
}
226
223
227
224
return errorsx .WithStack (fosite .ErrServerError .WithWrap (storageErr ).WithDebug (storageErr .Error ()))
0 commit comments