Handle null return for non-existent shared space keys
- Modify jsGet method to return null when key is not found - Add string-based error checking to differentiate between missing keys and other errors - Improve shared space key retrieval error handling in JavaScript bridge
This commit is contained in:
parent
dafd6b029b
commit
47da72bbee
1 changed files with 5 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ package assistant
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
v8 "github.com/yaoapp/gou/runtime/v8"
|
||||
|
|
@ -145,6 +146,10 @@ func jsGet(info *v8go.FunctionCallbackInfo) *v8go.Value {
|
|||
// Get the value
|
||||
value, err := global.ChatContext.SharedSpace.Get(key)
|
||||
if err != nil {
|
||||
// If the key is not found, return null
|
||||
if strings.Contains(err.Error(), "not found") {
|
||||
return v8go.Null(info.Context().Isolate())
|
||||
}
|
||||
return bridge.JsException(info.Context(), err.Error())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue