Refactor SUI core to handle backend script errors during page execution

This commit is contained in:
Max 2024-07-26 16:02:35 +08:00
parent 602333bd02
commit 6bcede11d9
2 changed files with 12 additions and 4 deletions

View file

@ -133,14 +133,14 @@ 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 error, please re-complie the page. %s", err.Error())
}
}
if c.Global != "" {
global, err := r.Request.ExecString(c.Global)
if err != nil {
return "", 500, fmt.Errorf("global data error, please re-complie the page %s", err.Error())
return "", 500, fmt.Errorf("global data error, please re-complie the page. %s", err.Error())
}
data["$global"] = global
}

View file

@ -126,7 +126,11 @@ func (r *Request) ExecString(data string) (Data, error) {
if err != nil {
return nil, err
}
r.Exec(res)
err = r.Exec(res)
if err != nil {
return nil, err
}
return res, nil
}
@ -288,7 +292,11 @@ func (r *Request) call(p interface{}) (interface{}, error) {
// Call the backend script
if r.Script != nil && strings.HasPrefix(processName, "@") {
method := processName[1:]
return r.Script.Call(r, method, processArgs...)
v, err := r.Script.Call(r, method, processArgs...)
if err != nil {
return nil, fmt.Errorf("backend script %s %s, please check the script", method, err.Error())
}
return v, nil
}
process, err := process.Of(processName, processArgs...)