diff --git a/controller/relay.go b/controller/relay.go index 8e7073f7..cf01f180 100644 --- a/controller/relay.go +++ b/controller/relay.go @@ -398,3 +398,15 @@ func RelayNotImplemented(c *gin.Context) { "error": err, }) } + +func RelayNotFound(c *gin.Context) { + err := OpenAIError{ + Message: fmt.Sprintf("API not found: %s:%s", c.Request.Method, c.Request.URL.Path), + Type: "one_api_error", + Param: "", + Code: "api_not_found", + } + c.JSON(http.StatusOK, gin.H{ + "error": err, + }) +} diff --git a/router/web-router.go b/router/web-router.go index 8f6d1ac4..19fc0c04 100644 --- a/router/web-router.go +++ b/router/web-router.go @@ -7,7 +7,9 @@ import ( "github.com/gin-gonic/gin" "net/http" "one-api/common" + "one-api/controller" "one-api/middleware" + "strings" ) func SetWebRouter(router *gin.Engine, buildFS embed.FS, indexPage []byte) { @@ -16,6 +18,10 @@ func SetWebRouter(router *gin.Engine, buildFS embed.FS, indexPage []byte) { router.Use(middleware.Cache()) router.Use(static.Serve("/", common.EmbedFolder(buildFS, "web/build"))) router.NoRoute(func(c *gin.Context) { + if strings.HasPrefix(c.Request.RequestURI, "/v1") { + controller.RelayNotFound(c) + return + } c.Header("Cache-Control", "no-cache") c.Data(http.StatusOK, "text/html; charset=utf-8", indexPage) })