micro-server-grpc/error.go
Vasiliy Tolstov 6b5eb3555b fix import paths for v2 release
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-09-20 15:11:08 +03:00

43 lines
904 B
Go

package grpc
import (
"net/http"
"github.com/micro/go-micro/v2/errors"
"google.golang.org/grpc/codes"
)
func microError(err *errors.Error) codes.Code {
switch err {
case nil:
return codes.OK
}
switch err.Code {
case http.StatusOK:
return codes.OK
case http.StatusBadRequest:
return codes.InvalidArgument
case http.StatusRequestTimeout:
return codes.DeadlineExceeded
case http.StatusNotFound:
return codes.NotFound
case http.StatusConflict:
return codes.AlreadyExists
case http.StatusForbidden:
return codes.PermissionDenied
case http.StatusUnauthorized:
return codes.Unauthenticated
case http.StatusPreconditionFailed:
return codes.FailedPrecondition
case http.StatusNotImplemented:
return codes.Unimplemented
case http.StatusInternalServerError:
return codes.Internal
case http.StatusServiceUnavailable:
return codes.Unavailable
}
return codes.Unknown
}