Browse Source

feat: support PluginInvokeError

Yeuoly 8 months ago
parent
commit
2c659c7799

+ 0 - 2
internal/core/plugin_daemon/generic.go

@@ -8,7 +8,6 @@ import (
 	"github.com/langgenius/dify-plugin-daemon/internal/core/plugin_daemon/backwards_invocation/transaction"
 	"github.com/langgenius/dify-plugin-daemon/internal/core/session_manager"
 	"github.com/langgenius/dify-plugin-daemon/internal/types/entities/plugin_entities"
-	"github.com/langgenius/dify-plugin-daemon/internal/utils/log"
 	"github.com/langgenius/dify-plugin-daemon/internal/utils/parser"
 	"github.com/langgenius/dify-plugin-daemon/internal/utils/stream"
 )
@@ -31,7 +30,6 @@ func GenericInvokePlugin[Req any, Rsp any](
 		case plugin_entities.SESSION_MESSAGE_TYPE_STREAM:
 			chunk, err := parser.UnmarshalJsonBytes[Rsp](chunk.Data)
 			if err != nil {
-				log.Error("unmarshal json failed: %s", err.Error())
 				response.WriteError(errors.New(parser.MarshalJson(map[string]string{
 					"error_type": "unmarshal_error",
 					"message":    fmt.Sprintf("unmarshal json failed: %s", err.Error()),

+ 1 - 1
internal/service/base_sse.go

@@ -50,7 +50,7 @@ func baseSSEService[R any](
 		for pluginDaemonResponse.Next() {
 			chunk, err := pluginDaemonResponse.Read()
 			if err != nil {
-				writeData(exception.InternalServerError(err).ToResponse())
+				writeData(exception.InvokePluginError(err).ToResponse())
 				break
 			}
 			writeData(entities.NewSuccessResponse(chunk))

+ 4 - 0
internal/types/exception/factory.go

@@ -29,3 +29,7 @@ func UnauthorizedError() PluginDaemonError {
 func PermissionDeniedError() PluginDaemonError {
 	return ErrorWithTypeAndCode("permission denied", "PluginPermissionDeniedError", -403)
 }
+
+func InvokePluginError(err error) PluginDaemonError {
+	return ErrorWithTypeAndCode(err.Error(), "PluginInvokeError", -500)
+}