From aaec2be2eec906ec83f837f009f0f103ba5ca353 Mon Sep 17 00:00:00 2001 From: Josh Yan Date: Wed, 17 Jul 2024 12:12:43 -0700 Subject: [PATCH] gin header --- server/routes.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/server/routes.go b/server/routes.go index 27f1951e1..5e3cdab72 100644 --- a/server/routes.go +++ b/server/routes.go @@ -614,12 +614,10 @@ func (s *Server) CreateModelHandler(c *gin.Context) { defer cancel() quantization := cmp.Or(r.Quantize, r.Quantization) - if err := CreateModel(ctx, name, filepath.Dir(r.Path), strings.ToUpper(quantization), f, fn); err != nil { - if errors.Is(err, errBadTemplate) { - c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()}) - } else { - ch <- gin.H{"error": err.Error()} - } + if err := CreateModel(ctx, name, filepath.Dir(r.Path), strings.ToUpper(quantization), f, fn); errors.Is(err, errBadTemplate) { + ch <- gin.H{"error": err.Error(), "status": http.StatusBadRequest} + } else if err != nil { + ch <- gin.H{"error": err.Error()} } }() @@ -1206,11 +1204,15 @@ func waitForStream(c *gin.Context, ch chan interface{}) { return } case gin.H: + status, ok := r["status"].(int) + if !ok { + status = http.StatusInternalServerError + } if errorMsg, ok := r["error"].(string); ok { - c.JSON(http.StatusInternalServerError, gin.H{"error": errorMsg}) + c.JSON(status, gin.H{"error": errorMsg}) return } else { - c.JSON(http.StatusInternalServerError, gin.H{"error": "unexpected error format in progress response"}) + c.JSON(status, gin.H{"error": "unexpected error format in progress response"}) return } default: