2019-04-17 11:09:44 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package errs2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"google.golang.org/grpc"
|
2019-09-19 05:46:39 +01:00
|
|
|
|
|
|
|
"storj.io/storj/pkg/rpc/rpcstatus"
|
2019-04-17 11:09:44 +01:00
|
|
|
)
|
|
|
|
|
2019-06-26 16:30:37 +01:00
|
|
|
// IsCanceled returns true, when the error is a cancellation.
|
|
|
|
func IsCanceled(err error) bool {
|
|
|
|
return errs.IsFunc(err, func(err error) bool {
|
2019-04-23 12:13:57 +01:00
|
|
|
return err == context.Canceled ||
|
2019-04-17 11:09:44 +01:00
|
|
|
err == grpc.ErrServerStopped ||
|
2019-08-05 15:46:32 +01:00
|
|
|
err == http.ErrServerClosed ||
|
2019-09-19 05:46:39 +01:00
|
|
|
rpcstatus.Code(err) == rpcstatus.Canceled
|
2019-06-26 16:30:37 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// IgnoreCanceled returns nil, when the operation was about canceling.
|
|
|
|
func IgnoreCanceled(err error) error {
|
|
|
|
if IsCanceled(err) {
|
2019-04-23 12:13:57 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|