1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-24 10:07:04 +02:00
go-micro/server/grpc/error.go

43 lines
904 B
Go
Raw Normal View History

2019-06-03 19:44:43 +02:00
package grpc
import (
"net/http"
"github.com/micro/go-micro/v2/errors"
2019-06-03 19:44:43 +02:00
"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
}