mirror of https://github.com/dapr/go-sdk.git
* return the specific error type of the actor state, caused by empty key or unmarshal fail Signed-off-by: wangxw <996268132@qq.com> * Update state_async_provider.go change log level of state load Signed-off-by: wXwcoder <996268132@qq.com> Signed-off-by: wangxw <996268132@qq.com> Signed-off-by: wXwcoder <996268132@qq.com>
This commit is contained in:
parent
c2dfec6abf
commit
014b4d6836
|
|
@ -15,6 +15,7 @@ package state
|
|||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
|
|
@ -23,6 +24,11 @@ import (
|
|||
client "github.com/dapr/go-sdk/client"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrStateEmpty = errors.New("get actor state result empty")
|
||||
ErrStateUnmarshal = errors.New("unmarshal state data error")
|
||||
)
|
||||
|
||||
type DaprStateAsyncProvider struct {
|
||||
daprClient client.Client
|
||||
stateSerializer codec.Codec
|
||||
|
|
@ -50,10 +56,12 @@ func (d *DaprStateAsyncProvider) Load(actorType, actorID, stateName string, repl
|
|||
return errors.Errorf("get actor state error = %s", err.Error())
|
||||
}
|
||||
if len(result.Data) == 0 {
|
||||
return errors.Errorf("get actor state result empty, with actorType: %s, actorID: %s, stateName %s", actorType, actorID, stateName)
|
||||
log.Errorf("get actor state result empty, with actorType: %s, actorID: %s, stateName %s", actorType, actorID, stateName)
|
||||
return ErrStateEmpty
|
||||
}
|
||||
if err := d.stateSerializer.Unmarshal(result.Data, reply); err != nil {
|
||||
return errors.Errorf("unmarshal state data error = %s", err.Error())
|
||||
log.Errorf("unmarshal state data error = %s", err.Error())
|
||||
return ErrStateUnmarshal
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue