mirror of
https://github.com/ollama/ollama.git
synced 2025-11-13 00:07:05 +01:00
server: serve original error for remote models
This commit is contained in:
@@ -29,7 +29,6 @@ import (
|
|||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
|
|
||||||
"github.com/ollama/ollama/api"
|
"github.com/ollama/ollama/api"
|
||||||
"github.com/ollama/ollama/auth"
|
|
||||||
"github.com/ollama/ollama/discover"
|
"github.com/ollama/ollama/discover"
|
||||||
"github.com/ollama/ollama/envconfig"
|
"github.com/ollama/ollama/envconfig"
|
||||||
"github.com/ollama/ollama/format"
|
"github.com/ollama/ollama/format"
|
||||||
@@ -251,18 +250,14 @@ func (s *Server) GenerateHandler(c *gin.Context) {
|
|||||||
client := api.NewClient(remoteURL, http.DefaultClient)
|
client := api.NewClient(remoteURL, http.DefaultClient)
|
||||||
err = client.Generate(c, &req, fn)
|
err = client.Generate(c, &req, fn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var sErr api.AuthorizationError
|
var authError api.AuthorizationError
|
||||||
if errors.As(err, &sErr) && sErr.StatusCode == http.StatusUnauthorized {
|
if errors.As(err, &authError) {
|
||||||
pk, pkErr := auth.GetPublicKey()
|
c.JSON(authError.StatusCode, gin.H{"error": "unauthorized", "public_key": authError.PublicKey})
|
||||||
if pkErr != nil {
|
|
||||||
slog.Error("couldn't get public key", "error", pkErr)
|
|
||||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "error getting public key"})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusUnauthorized, gin.H{
|
var apiError api.StatusError
|
||||||
"error": "unauthorized",
|
if errors.As(err, &apiError) {
|
||||||
"public_key": pk,
|
c.JSON(apiError.StatusCode, apiError)
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
@@ -1813,18 +1808,14 @@ 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
|
var authError api.AuthorizationError
|
||||||
if errors.As(err, &sErr) && sErr.StatusCode == http.StatusUnauthorized {
|
if errors.As(err, &authError) {
|
||||||
pk, pkErr := auth.GetPublicKey()
|
c.JSON(authError.StatusCode, gin.H{"error": "unauthorized", "public_key": authError.PublicKey})
|
||||||
if pkErr != nil {
|
|
||||||
slog.Error("couldn't get public key", "error", pkErr)
|
|
||||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "error getting public key"})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusUnauthorized, gin.H{
|
var apiError api.StatusError
|
||||||
"error": "unauthorized",
|
if errors.As(err, &apiError) {
|
||||||
"public_key": pk,
|
c.JSON(apiError.StatusCode, apiError)
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
|||||||
Reference in New Issue
Block a user