This commit is contained in:
24
pkg/grpcerr/grpcerr.go
Normal file
24
pkg/grpcerr/grpcerr.go
Normal file
@@ -0,0 +1,24 @@
|
||||
// Package grpcerr has the handful of status-coded error constructors
|
||||
// every service's interfaces/grpc package uses, so "not found" maps to
|
||||
// codes.NotFound the same way in all eight of them instead of each
|
||||
// service inventing its own convention.
|
||||
package grpcerr
|
||||
|
||||
import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func NotFound(what string) error { return status.Errorf(codes.NotFound, "%s not found", what) }
|
||||
func InvalidArgument(msg string) error { return status.Error(codes.InvalidArgument, msg) }
|
||||
func FailedPrecondition(msg string) error { return status.Error(codes.FailedPrecondition, msg) }
|
||||
func ResourceExhausted(msg string) error { return status.Error(codes.ResourceExhausted, msg) }
|
||||
func Internal(err error) error { return status.Error(codes.Internal, err.Error()) }
|
||||
func Unauthenticated(msg string) error { return status.Error(codes.Unauthenticated, msg) }
|
||||
|
||||
// Unavailable maps a dependency that is reachable-in-principle but not
|
||||
// reachable right now (a vLLM deployment stuck Pending/restarting, a
|
||||
// downstream service mid-rollout) onto codes.Unavailable instead of
|
||||
// codes.Internal — gRPC clients and well-behaved gateways treat
|
||||
// Unavailable as safe-to-retry, which an opaque Internal never is.
|
||||
func Unavailable(err error) error { return status.Error(codes.Unavailable, err.Error()) }
|
||||
Reference in New Issue
Block a user