123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package http
- import (
- "google.golang.org/grpc/codes"
- "net/http"
- )
- func httpStatusFromGrpcCode(code codes.Code) int {
- switch code {
- case codes.OK:
- return http.StatusOK
- case codes.Canceled:
- return http.StatusRequestTimeout
- case codes.Unknown:
- return http.StatusInternalServerError
- case codes.InvalidArgument:
- return http.StatusBadRequest
- case codes.DeadlineExceeded:
- return http.StatusGatewayTimeout
- case codes.ResourceExhausted:
- return http.StatusTooManyRequests
- case codes.FailedPrecondition:
- return http.StatusBadRequest
- case codes.OutOfRange:
- return http.StatusBadRequest
- case codes.Unimplemented:
- return http.StatusNotImplemented
- case codes.Internal:
- return http.StatusInternalServerError
- case codes.Unavailable:
- return http.StatusServiceUnavailable
- case codes.DataLoss:
- return http.StatusInternalServerError
- case codes.NotFound:
- return http.StatusNotFound
- case codes.Unauthenticated:
- return http.StatusUnauthorized
- case codes.PermissionDenied:
- return http.StatusForbidden
- }
- return http.StatusInternalServerError
- }
|