mirror of
https://github.com/rclone/rclone.git
synced 2024-12-26 08:58:58 +01:00
31 lines
648 B
Go
31 lines
648 B
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package errs2
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"storj.io/common/internal/grpchook"
|
|
"storj.io/common/rpc/rpcstatus"
|
|
)
|
|
|
|
// IsCanceled returns true, when the error is a cancellation.
|
|
func IsCanceled(err error) bool {
|
|
return errs.IsFunc(err, func(err error) bool {
|
|
return err == context.Canceled ||
|
|
grpchook.IsErrServerStopped(err) ||
|
|
rpcstatus.Code(err) == rpcstatus.Canceled
|
|
})
|
|
}
|
|
|
|
// IgnoreCanceled returns nil, when the operation was about canceling.
|
|
func IgnoreCanceled(err error) error {
|
|
if IsCanceled(err) {
|
|
return nil
|
|
}
|
|
return err
|
|
}
|