use new err

This commit is contained in:
Josh Yan 2024-07-17 11:35:34 -07:00
parent 3e89435605
commit 9b5bf861dd
2 changed files with 3 additions and 2 deletions

View File

@ -494,7 +494,7 @@ func CreateModel(ctx context.Context, name model.Name, modelFileDir, quantizatio
case "license", "template", "system": case "license", "template", "system":
if c.Name == "template" { if c.Name == "template" {
if _, err := template.Parse(c.Args); err != nil { if _, err := template.Parse(c.Args); err != nil {
return err return fmt.Errorf("%w: %s", errBadTemplate, err)
} }
} }

View File

@ -56,6 +56,7 @@ func init() {
} }
var errRequired = errors.New("is required") var errRequired = errors.New("is required")
var errBadTemplate = errors.New("template error")
func modelOptions(model *Model, requestOpts map[string]interface{}) (api.Options, error) { func modelOptions(model *Model, requestOpts map[string]interface{}) (api.Options, error) {
opts := api.DefaultOptions() opts := api.DefaultOptions()
@ -614,7 +615,7 @@ func (s *Server) CreateModelHandler(c *gin.Context) {
quantization := cmp.Or(r.Quantize, r.Quantization) quantization := cmp.Or(r.Quantize, r.Quantization)
if err := CreateModel(ctx, name, filepath.Dir(r.Path), strings.ToUpper(quantization), f, fn); err != nil { if err := CreateModel(ctx, name, filepath.Dir(r.Path), strings.ToUpper(quantization), f, fn); err != nil {
if strings.HasPrefix(err.Error(), "template: ") { if errors.Is(err, errBadTemplate) {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
} else { } else {
ch <- gin.H{"error": err.Error()} ch <- gin.H{"error": err.Error()}