Merge pull request #1086 from go-redis/fix/hooks-after-process

Call all After* hooks and return first error
This commit is contained in:
Vladimir Mihailenco 2019-07-09 10:19:04 +03:00 committed by GitHub
commit 5a3e8ba7f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

@ -66,14 +66,15 @@ func (hs hooks) beforeProcess(ctx context.Context, cmd Cmder) (context.Context,
}
func (hs hooks) afterProcess(ctx context.Context, cmd Cmder) (context.Context, error) {
var firstErr error
for _, h := range hs.hooks {
var err error
ctx, err = h.AfterProcess(ctx, cmd)
if err != nil {
return nil, err
if err != nil && firstErr == nil {
firstErr = err
}
}
return ctx, nil
return ctx, firstErr
}
func (hs hooks) processPipeline(
@ -106,14 +107,15 @@ func (hs hooks) beforeProcessPipeline(ctx context.Context, cmds []Cmder) (contex
}
func (hs hooks) afterProcessPipeline(ctx context.Context, cmds []Cmder) (context.Context, error) {
var firstErr error
for _, h := range hs.hooks {
var err error
ctx, err = h.AfterProcessPipeline(ctx, cmds)
if err != nil {
return nil, err
if err != nil && firstErr == nil {
firstErr = err
}
}
return ctx, nil
return ctx, firstErr
}
//------------------------------------------------------------------------------