status

package
v1.2.115 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Errore

func Errore(err error, c codes.Code, msg string) error

Errore returns an error representing c and msg if err is not status.Status. If c is OK, returns nil. If err is status.Status already, return err. else, return an error representing c and msg marked with err.

func Errorfe added in v1.2.6

func Errorfe(err error, c codes.Code, format string, a ...interface{}) error

Errorfe returns Errore(c, fmt.Sprintf(format, a...)).

func GetErrorWithLocalizedMessage

func GetErrorWithLocalizedMessage(err error, locale string) error

GetErrorWithLocalizedMessage is a convenience function which removes the need to handle the error which may be not Status from GetLocalizedMessageError.

func GetLocalizedMessage

func GetLocalizedMessage(s *Status, locale string) string

GetLocalizedMessage returns an error that formats as the given Status with locale message or message. The locale used following the specification defined at http://www.rfc-editor.org/rfc/bcp/bcp47.txt. Examples are: "en-US", "fr-CH", "es-MX", "zh-CN" advice: use locale generated by golang.org/x/text/language.Tag "en-US" : language.AmericanEnglish.String() "zh-CN" : language.SimplifiedChinese.String()

func GetLocalizedMessageError

func GetLocalizedMessageError(s *Status, locale string) error

GetLocalizedMessageError is a convenience function which returns an error that formats as the given Status with locale message or message.

func GetLocalizedMessageFromError

func GetLocalizedMessageFromError(err error, locale string) string

GetLocalizedMessageFromError is a convenience function which removes the need to handle the error which may be not Status from GetLocalizedMessage.

Types

type Status

type Status = status.Status

func Convert

func Convert(err error) *Status

Convert is a convenience function which removes the need to handle the boolean return value from FromError. Deprecated: As of grpc 1.58.0, Use status.Convert instead.

func FromError deprecated

func FromError(err error) (s *Status, ok bool)

FromError returns a Status representation of err.

  • If err was produced by this package or implements the method `GRPCStatus() *Status` and `GRPCStatus()` does not return nil, or if err wraps a type satisfying this, the Status from `GRPCStatus()` is returned. For wrapped errors, the message returned contains the entire err.Error() text and not just the wrapped status. In that case, ok is true.

  • If err is nil, a Status is returned with codes.OK and no message, and ok is true.

  • If err implements the method `GRPCStatus() *Status` and `GRPCStatus()` returns nil (which maps to Codes.OK), or if err wraps a type satisfying this, a Status is returned with codes.Unknown and err's Error() message, and ok is false.

  • Otherwise, err is an error not compatible with this package. In this case, a Status is returned with codes.Unknown and err's Error() message, and ok is false.

Deprecated: As of grpc 1.58.0, Use status.FromError instead.

func WithBadRequestDetails

func WithBadRequestDetails(s *Status, descByField map[string]string) (*Status, error)

WithBadRequestDetails returns a new status with the provided bad requests messages appended to the status.

Jump to

Keyboard shortcuts

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