Files
teleport/integrations/lib/errors.go
T
Justinas Stankevičius 6af6e7f566 Vendor slack plugin and supporting libraries (#23045)
* Vendor slack plugin and supporting libraries

* Fix up plugin integration tests (wip)

* Run GCI on vendored code

* Use newtype instead of type alias

golangci-lint currently panics on this,
"skip-files" et al don't help, as it is a linter panic, not an error

See https://github.com/dominikh/go-tools/commit/d717045480130461e1e777ead7f2981621f0d9f0

* Remove long-runing plugins tests from difftest

* Move access plugin tests to unit-tests-integrations
2023-03-22 19:39:07 +00:00

52 lines
1.6 KiB
Go

// Copyright 2023 Gravitational, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package lib
import (
"context"
"io"
"github.com/gravitational/trace"
"github.com/gravitational/trace/trail"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// TODO: remove this when trail.FromGRPC will understand additional error codes
func FromGRPC(err error) error {
switch {
case err == io.EOF:
fallthrough
case status.Code(err) == codes.Canceled, err == context.Canceled:
fallthrough
case status.Code(err) == codes.DeadlineExceeded, err == context.DeadlineExceeded:
return trace.Wrap(err)
default:
return trail.FromGRPC(err)
}
}
// TODO: remove this when trail.FromGRPC will understand additional error codes
func IsCanceled(err error) bool {
err = trace.Unwrap(err)
return err == context.Canceled || status.Code(err) == codes.Canceled
}
// TODO: remove this when trail.FromGRPC will understand additional error codes
func IsDeadline(err error) bool {
err = trace.Unwrap(err)
return err == context.DeadlineExceeded || status.Code(err) == codes.DeadlineExceeded
}