Improve error handling in request value execution

- Modify request value execution to log errors when method calls fail
- Prevent propagation of errors during value resolution
- Update error message in data merging to be more descriptive
This commit is contained in:
Max 2025-03-06 10:48:27 +08:00
parent 47da72bbee
commit e59dacefa2
2 changed files with 7 additions and 2 deletions

View file

@ -141,7 +141,7 @@ func (r *Request) Render() (string, int, error) {
if c.Data != "" {
err = r.Request.ExecStringMerge(data, c.Data)
if err != nil {
return "", 500, fmt.Errorf("data error, please re-complie the page. %s", err.Error())
return "", 500, fmt.Errorf("data merge error, please re-complie the page. %s", err.Error())
}
}

View file

@ -218,7 +218,12 @@ func (r *Request) execValue(value interface{}) (interface{}, error) {
}
if strings.HasPrefix(v, "$") {
return r.call(strings.TrimLeft(v, "$"))
res, err := r.call(strings.TrimLeft(v, "$"))
if err != nil {
log.Error("[Request] Exec value:%s, %s", v, err.Error())
return nil, nil
}
return res, nil
}
return v, nil