Documentation ¶
Index ¶
- Constants
- func Code(err error) int
- func Errorf(code int, message, format string, a ...any) error
- func FromGRPCCode(code codes.Code) int
- func IsBadRequest(err error) bool
- func IsClientClosed(err error) bool
- func IsConflict(err error) bool
- func IsForbidden(err error) bool
- func IsGatewayTimeout(err error) bool
- func IsInternalServer(err error) bool
- func IsNotFound(err error) bool
- func IsServiceUnavailable(err error) bool
- func IsUnauthorized(err error) bool
- func Message(err error) string
- func ToGRPCCode(code int) codes.Code
- type Converter
- type Error
- func ErrBadRequest(detail string) *Error
- func ErrBadRequestf(format string, args ...any) *Error
- func ErrClientClosed(message string) *Error
- func ErrClientClosedf(format string, args ...any) *Error
- func ErrConflict(detail string) *Error
- func ErrConflictf(format string, args ...any) *Error
- func ErrForbidden(detail string) *Error
- func ErrForbiddenf(format string, args ...any) *Error
- func ErrGatewayTimeout(detail string) *Error
- func ErrGatewayTimeoutf(format string, args ...any) *Error
- func ErrInternalServer(detail string) *Error
- func ErrInternalServerf(format string, args ...any) *Error
- func ErrNotFound(detail string) *Error
- func ErrNotFoundf(format string, args ...any) *Error
- func ErrServiceUnavailable(detail string) *Error
- func ErrServiceUnavailablef(format string, args ...any) *Error
- func ErrUnauthorized(detail string) *Error
- func ErrUnauthorizedf(format string, args ...any) *Error
- func FromError(err error) *Error
- func New(code int, message, detail string) *Error
- func Newf(code int, message, format string, a ...any) *Error
- func Parse(err string) *Error
Constants ¶
const ( // ClientClosed is non-standard http status code, // which defined by nginx. // https://httpstatus.in/499/ ClientClosed = 499 )
Variables ¶
This section is empty.
Functions ¶
func FromGRPCCode ¶
FromGRPCCode converts a gRPC error code into the corresponding HTTP response status.
func IsBadRequest ¶
IsBadRequest determines if err is an error which indicates a BadRequest error. It supports wrapped errors.
func IsClientClosed ¶
IsClientClosed determines if err is an error which indicates a IsClientClosed error. It supports wrapped errors.
func IsConflict ¶
IsConflict determines if err is an error which indicates a Conflict error. It supports wrapped errors.
func IsForbidden ¶
IsForbidden determines if err is an error which indicates a Forbidden error. It supports wrapped errors.
func IsGatewayTimeout ¶
IsGatewayTimeout determines if err is an error which indicates a GatewayTimeout error. It supports wrapped errors.
func IsInternalServer ¶
func IsNotFound ¶
IsNotFound determines if err is an error which indicates an NotFound error. It supports wrapped errors.
func IsServiceUnavailable ¶
IsServiceUnavailable determines if err is an error which indicates a Unavailable error. It supports wrapped errors.
func IsUnauthorized ¶
IsUnauthorized determines if err is an error which indicates a Unauthorized error. It supports wrapped errors.
func ToGRPCCode ¶
ToGRPCCode converts an HTTP error code into the corresponding gRPC response status.
Types ¶
type Converter ¶
type Converter interface { // ToGRPCCode converts an HTTP error code into the corresponding gRPC response status. ToGRPCCode(code int) codes.Code // FromGRPCCode converts a gRPC error code into the corresponding HTTP response status. FromGRPCCode(code codes.Code) int }
var DefaultConverter Converter = statusConverter{}
type Error ¶
type Error struct { Code int32 `json:"code,omitempty"` Message string `json:"message,omitempty"` Detail string `json:"detail,omitempty"` Metadata map[string]string `json:"metadata,omitempty"` }
func ErrBadRequest ¶
ErrBadRequest new BadRequest error that is mapped to a 400 response.
func ErrBadRequestf ¶
ErrBadRequestf new BadRequest error that is mapped to a 400 response.
func ErrClientClosed ¶
ErrClientClosed new ClientClosed error that is mapped to a HTTP 499 response.
func ErrClientClosedf ¶
ErrClientClosed new ClientClosed error that is mapped to a HTTP 499 response.
func ErrConflict ¶
ErrConflict new Conflict error that is mapped to a 409 response.
func ErrConflictf ¶
ErrConflictf new Conflict error that is mapped to a 409 response.
func ErrForbidden ¶
ErrForbidden new Forbidden error that is mapped to a 403 response.
func ErrForbiddenf ¶
ErrForbiddenf new Forbidden error that is mapped to a 403 response.
func ErrGatewayTimeout ¶
ErrGatewayTimeout new GatewayTimeout error that is mapped to a HTTP 504 response.
func ErrGatewayTimeoutf ¶
ErrGatewayTimeoutf new GatewayTimeout error that is mapped to a HTTP 504 response.
func ErrInternalServer ¶
func ErrInternalServerf ¶
func ErrNotFound ¶
ErrNotFound new NotFound error that is mapped to a 404 response.
func ErrNotFoundf ¶
ErrNotFoundf new NotFound error that is mapped to a 404 response.
func ErrServiceUnavailable ¶
ErrServiceUnavailable new ServiceUnavailable error that is mapped to a HTTP 503 response.
func ErrServiceUnavailablef ¶
ErrServiceUnavailablef new ServiceUnavailable error that is mapped to a HTTP 503 response.
func ErrUnauthorized ¶
ErrUnauthorized new Unauthorized error that is mapped to a 401 response.
func ErrUnauthorizedf ¶
ErrUnauthorized new Unauthorized error that is mapped to a 401 response.
func (*Error) GRPCStatus ¶
GRPCStatus returns the Status represented by se.