Merge pull request #890 from trheyi/main
Handle null return for non-existent shared space keys
This commit is contained in:
commit
1a7d54040c
1 changed files with 5 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ package assistant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
v8 "github.com/yaoapp/gou/runtime/v8"
|
v8 "github.com/yaoapp/gou/runtime/v8"
|
||||||
|
|
@ -145,6 +146,10 @@ func jsGet(info *v8go.FunctionCallbackInfo) *v8go.Value {
|
||||||
// Get the value
|
// Get the value
|
||||||
value, err := global.ChatContext.SharedSpace.Get(key)
|
value, err := global.ChatContext.SharedSpace.Get(key)
|
||||||
if err != nil {
|
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())
|
return bridge.JsException(info.Context(), err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue