panic handling

This commit is contained in:
tobi 2025-03-03 14:48:00 +01:00
commit 668dbf2b4d

View file

@ -186,13 +186,9 @@ func (s *s) HandleTokenRequest(r *http.Request) (map[string]interface{}, gtserro
// from serialization so that clients don't // from serialization so that clients don't
// interpret the token as already expired. // interpret the token as already expired.
if expiresInI, ok := data["expires_in"]; ok { if expiresInI, ok := data["expires_in"]; ok {
expiresIn, ok := expiresInI.(int64) // This will panic if expiresIn is
if !ok { // not an int64, which is what we want.
log.Panicf(ctx, "could not cast expires_in %T as int64", expiresInI) if expiresInI.(int64) <= 0 {
return nil, nil
}
if expiresIn <= 0 {
delete(data, "expires_in") delete(data, "expires_in")
} }
} }
@ -275,13 +271,9 @@ func (s *s) HandleAuthorizeRequest(w http.ResponseWriter, r *http.Request) gtser
return gtserror.NewErrorUnauthorized(err, HelpfulAdvice) return gtserror.NewErrorUnauthorized(err, HelpfulAdvice)
} }
app, ok := client.(*gtsmodel.Application) // This will panic if client is not a
if !ok { // *gtsmodel.Application, which is what we want.
log.Panicf(ctx, "could not cast %T to *gtsmodel.Application", client) req.RedirectURI = client.(*gtsmodel.Application).RedirectURIs[0]
return nil
}
req.RedirectURI = app.RedirectURIs[0]
} }
uri, err := s.server.GetRedirectURI(req, s.server.GetAuthorizeData(req.ResponseType, ti)) uri, err := s.server.GetRedirectURI(req, s.server.GetAuthorizeData(req.ResponseType, ti))