mirror of
https://github.com/likelovewant/ollama-for-amd.git
synced 2025-12-22 06:43:57 +00:00
server: add unauthorized error to remote chat handler (#12338)
This commit is contained in:
@@ -259,7 +259,10 @@ func (s *Server) GenerateHandler(c *gin.Context) {
|
|||||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "error getting public key"})
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "error getting public key"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusUnauthorized, gin.H{"public_key": pk})
|
c.JSON(http.StatusUnauthorized, gin.H{
|
||||||
|
"error": "unauthorized",
|
||||||
|
"public_key": pk,
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
@@ -1810,6 +1813,20 @@ func (s *Server) ChatHandler(c *gin.Context) {
|
|||||||
client := api.NewClient(remoteURL, http.DefaultClient)
|
client := api.NewClient(remoteURL, http.DefaultClient)
|
||||||
err = client.Chat(c, &req, fn)
|
err = client.Chat(c, &req, fn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
var sErr api.AuthorizationError
|
||||||
|
if errors.As(err, &sErr) && sErr.StatusCode == http.StatusUnauthorized {
|
||||||
|
pk, pkErr := auth.GetPublicKey()
|
||||||
|
if pkErr != nil {
|
||||||
|
slog.Error("couldn't get public key", "error", pkErr)
|
||||||
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "error getting public key"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusUnauthorized, gin.H{
|
||||||
|
"error": "unauthorized",
|
||||||
|
"public_key": pk,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user