Denis Kirillov
462589fc0c
All checks were successful
/ Vulncheck (pull_request) Successful in 1m42s
/ Lint (pull_request) Successful in 3m31s
/ Tests (1.19) (pull_request) Successful in 2m57s
/ Tests (1.20) (pull_request) Successful in 3m4s
/ Builds (1.19) (pull_request) Successful in 2m35s
/ Builds (1.20) (pull_request) Successful in 2m39s
/ DCO (pull_request) Successful in 1m7s
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
42 lines
855 B
Go
42 lines
855 B
Go
package errors
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
func UnwrapErr(err error) error {
|
|
unwrappedErr := errors.Unwrap(err)
|
|
for unwrappedErr != nil {
|
|
err = unwrappedErr
|
|
unwrappedErr = errors.Unwrap(err)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func IsErrObjectAccessDenied(err error) (string, bool) {
|
|
err = UnwrapErr(err)
|
|
switch err := err.(type) {
|
|
default:
|
|
return "", false
|
|
case apistatus.ObjectAccessDenied:
|
|
return err.Reason(), true
|
|
case *apistatus.ObjectAccessDenied:
|
|
return err.Reason(), true
|
|
}
|
|
}
|
|
|
|
func IsTimeoutError(err error) bool {
|
|
if strings.Contains(err.Error(), "timeout") ||
|
|
errors.Is(err, context.DeadlineExceeded) {
|
|
return true
|
|
}
|
|
|
|
return status.Code(UnwrapErr(err)) == codes.DeadlineExceeded
|
|
}
|