grpcerrors

package
v0.28.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RequestCanceledMessage         = "request canceled"
	RequestDeadlineExceededMessage = "request deadline exceeded"
)

Variables

This section is empty.

Functions

func AlreadyExists

func AlreadyExists(err error, message string) error

AlreadyExists wraps err as an already-exists error for the grpc-gateway sanitizer.

func Code

func Code(err error) codes.Code

Code returns the gRPC code from a handler or status error.

func FailedPrecondition

func FailedPrecondition(err error, message string) error

FailedPrecondition wraps err as a failed-precondition error for the grpc-gateway sanitizer.

func HandlerMessage

func HandlerMessage(err error) (string, bool)

HandlerMessage returns the client-safe message from a handler error.

func HandlerStatus

func HandlerStatus(err error) (codes.Code, string, bool)

HandlerStatus returns the gRPC code and client-safe message from a handler error.

func Internal

func Internal(err error, message string) error

Internal wraps err as an internal server error for the grpc-gateway sanitizer.

func InvalidArgument

func InvalidArgument(err error, message string) error

InvalidArgument wraps err as an invalid-argument error for the grpc-gateway sanitizer.

func NotFound

func NotFound(err error, message string) error

NotFound wraps err as a not-found error for the grpc-gateway sanitizer.

func PermissionDenied

func PermissionDenied(err error, message string) error

PermissionDenied wraps err as a permission-denied error for the grpc-gateway sanitizer.

func ResourceExhausted

func ResourceExhausted(err error, message string) error

ResourceExhausted wraps err as a resource-exhausted error for the grpc-gateway sanitizer.

func StatusFromContextError

func StatusFromContextError(requestCtx context.Context, err error) (ok bool, statusErr error)

StatusFromContextError maps context cancellation errors to gRPC status codes suitable for HTTP translation via grpc-gateway:

  • context.Canceled (typically client disconnect) -> codes.Canceled (HTTP 499)
  • context.DeadlineExceeded -> codes.DeadlineExceeded (HTTP 504)

requestCtx should be the incoming HTTP/gRPC request context. When the client disconnects, requestCtx.Err() is set and Canceled is returned — see Brandur's notes on distinguishing local vs request context: https://brandur.org/fragments/testing-request-cancellation

func Unauthenticated

func Unauthenticated(err error, message string) error

Unauthenticated wraps err as an unauthenticated error for the grpc-gateway sanitizer.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL