@@ -228,9 +228,6 @@ func (s *Server) GetAuthorizeData(rt oauth2.ResponseType, ti oauth2.TokenInfo) (
228228func (s * Server ) GetErrorData (rerr , ierr error ) (data map [string ]interface {}, statusCode int ) {
229229 if ierr != nil {
230230 rerr = errors .ErrServerError
231- if fn := s .InternalErrorHandler ; fn != nil {
232- fn (ierr )
233- }
234231 }
235232 re := & errors.Response {
236233 Error : rerr ,
@@ -253,11 +250,18 @@ func (s *Server) GetErrorData(rerr, ierr error) (data map[string]interface{}, st
253250}
254251
255252// response redirect error
256- func (s * Server ) resRedirectError (w http.ResponseWriter , req * AuthorizeRequest , rerr , ierr error ) (err error ) {
253+ func (s * Server ) resRedirectError (w http.ResponseWriter , r * http. Request , req * AuthorizeRequest , rerr , ierr error ) (err error ) {
257254 if req == nil {
258255 err = ierr
259256 return
260257 }
258+ if fn := s .InternalErrorHandler ; fn != nil {
259+ verr := ierr
260+ if verr == nil {
261+ verr = rerr
262+ }
263+ fn (r , verr )
264+ }
261265 data , _ := s .GetErrorData (rerr , ierr )
262266 err = s .resRedirect (w , req , data )
263267 return
@@ -283,20 +287,20 @@ func (s *Server) HandleAuthorizeRequest(w http.ResponseWriter, r *http.Request)
283287 }()
284288 req , rerr , ierr := s .ValidationAuthorizeRequest (r )
285289 if rerr != nil || ierr != nil {
286- err = s .resRedirectError (w , req , rerr , ierr )
290+ err = s .resRedirectError (w , r , req , rerr , ierr )
287291 return
288292 }
289293 userID , err := s .UserAuthorizationHandler (w , r )
290294 if err != nil {
291- err = s .resRedirectError (w , req , nil , err )
295+ err = s .resRedirectError (w , r , req , nil , err )
292296 return
293297 } else if userID == "" {
294298 return
295299 }
296300 req .UserID = userID
297301 ti , rerr , ierr := s .GetAuthorizeToken (req )
298302 if rerr != nil || ierr != nil {
299- err = s .resRedirectError (w , req , rerr , ierr )
303+ err = s .resRedirectError (w , r , req , rerr , ierr )
300304 return
301305 }
302306 err = s .resRedirect (w , req , s .GetAuthorizeData (req .ResponseType , ti ))
@@ -460,19 +464,26 @@ func (s *Server) HandleTokenRequest(w http.ResponseWriter, r *http.Request) (err
460464 }()
461465 gt , tgr , rerr , ierr := s .ValidationTokenRequest (r )
462466 if rerr != nil || ierr != nil {
463- err = s .resTokenError (w , rerr , ierr )
467+ err = s .resTokenError (w , r , rerr , ierr )
464468 return
465469 }
466470 ti , rerr , ierr := s .GetAccessToken (gt , tgr )
467471 if rerr != nil || ierr != nil {
468- err = s .resTokenError (w , rerr , ierr )
472+ err = s .resTokenError (w , r , rerr , ierr )
469473 return
470474 }
471475 err = s .resToken (w , s .GetTokenData (ti ))
472476 return
473477}
474478
475- func (s * Server ) resTokenError (w http.ResponseWriter , rerr , ierr error ) (err error ) {
479+ func (s * Server ) resTokenError (w http.ResponseWriter , r * http.Request , rerr , ierr error ) (err error ) {
480+ if fn := s .InternalErrorHandler ; fn != nil {
481+ verr := ierr
482+ if verr == nil {
483+ verr = rerr
484+ }
485+ fn (r , verr )
486+ }
476487 data , statusCode := s .GetErrorData (rerr , ierr )
477488 s .resToken (w , data , statusCode )
478489 return
0 commit comments