Merge pull request #38450 from thaJeztah/remove_deprecated_grpc_functions

Replace deprecated grpc.ErrorDesc() and grpc.Code() calls
This commit is contained in:
Brian Goff 2019-01-04 16:46:49 -08:00 committed by GitHub
commit 6825db8c94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -9,8 +9,8 @@ import (
"github.com/docker/docker/errdefs"
"github.com/gorilla/mux"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type causer interface {
@ -89,14 +89,14 @@ func MakeErrorHandler(err error) http.HandlerFunc {
}
WriteJSON(w, statusCode, response)
} else {
http.Error(w, grpc.ErrorDesc(err), statusCode)
http.Error(w, status.Convert(err).Message(), statusCode)
}
}
}
// statusCodeFromGRPCError returns status code according to gRPC error
func statusCodeFromGRPCError(err error) int {
switch grpc.Code(err) {
switch status.Code(err) {
case codes.InvalidArgument: // code 3
return http.StatusBadRequest
case codes.NotFound: // code 5

View file

@ -7,7 +7,7 @@ import (
"github.com/docker/docker/errdefs"
"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/status"
)
func errNotRunning(id string) error {
@ -122,7 +122,7 @@ func (e startInvalidConfigError) Error() string {
func (e startInvalidConfigError) InvalidParameter() {} // Is this right???
func translateContainerdStartErr(cmd string, setExitCode func(int), err error) error {
errDesc := grpc.ErrorDesc(err)
errDesc := status.Convert(err).Message()
contains := func(s1, s2 string) bool {
return strings.Contains(strings.ToLower(s1), s2)
}