Documentation ¶
Overview ¶
Package rpcerr provides a way to return detailed information for an RPC request error. The error is normally JSON encoded.
Index ¶
- Constants
- Variables
- func BadRequest(format string, obj ...any) error
- func Code(err error) int
- func Conflict(format string, obj ...any) error
- func Equal(err1 error, err2 error) bool
- func Forbidden(format string, obj ...any) error
- func InternalServerError(format string, obj ...any) error
- func LookupID(code int32) (string, bool)
- func MethodNotAllowed(format string, obj ...any) error
- func New(id string, code int32, detail string) error
- func NewCode(code int32, detail string) error
- func NewCodeFormat(code int32, format string, args ...any) error
- func NewFormat(id string, code int32, format string, args ...any) error
- func NotFound(format string, obj ...any) error
- func RegisterCode(code int32, id string)
- func RequestEntityTooLarge(format string, obj ...any) error
- func Timeout(format string, obj ...any) error
- func TooManyRequests(format string, obj ...any) error
- func Unauthorized(format string, obj ...any) error
- type Error
- func (*Error) Descriptor() ([]byte, []int)deprecated
- func (obj *Error) Error() string
- func (x *Error) GetCode() int32
- func (x *Error) GetDetail() string
- func (x *Error) GetId() string
- func (x *Error) GetMessage() string
- func (obj *Error) Is(err error) bool
- func (*Error) ProtoMessage()
- func (x *Error) ProtoReflect() protoreflect.Message
- func (x *Error) Reset()
- func (obj *Error) Status() string
- func (x *Error) String() string
- func (m *Error) Validate() error
- func (m *Error) ValidateAll() error
- type ErrorMultiError
- type ErrorValidationError
- type MultiError
- func (e *MultiError) Append(err *Error)
- func (*MultiError) Descriptor() ([]byte, []int)deprecated
- func (e *MultiError) Error() string
- func (x *MultiError) GetErrors() []*Error
- func (e *MultiError) HasErrors() bool
- func (*MultiError) ProtoMessage()
- func (x *MultiError) ProtoReflect() protoreflect.Message
- func (x *MultiError) Reset()
- func (x *MultiError) String() string
- func (m *MultiError) Validate() error
- func (m *MultiError) ValidateAll() error
- type MultiErrorMultiError
- type MultiErrorValidationError
Constants ¶
const ( UnknownID = "http.response.status.unknown" // ID for Unknown status BadRequestID = "http.response.status.bad_request" // ID for Bad Request status ForbiddenID = "http.response.status.forbidden" // ID for Forbidden status NotFoundID = "http.response.status.not_found" // ID for Not Found status MethodNotAllowedID = "http.response.status.method_not_allowed" // ID for Method Not Allowed status TooManyRequestsID = "http.response.status.too_many_requests" // ID for Too Many Requests status RequestEntityTooLargeID = "http.response.status.request_entity_too_large" // ID for Request Entity Too Large status InternalServerErrorID = "http.response.status.internal_server_error" // ID for Internal Server Error status ConflictID = "http.response.status.conflict" // ID for Conflict status RequestTimeoutID = "http.response.status.request_timeout" // ID for Request Timeout status )
Define constant IDs for various Error status codes
Variables ¶
var File_rpcerr_rpcerr_proto protoreflect.FileDescriptor
Functions ¶
func BadRequest ¶
BadRequest generates a 400 error.
func InternalServerError ¶
InternalServerError generates a 500 error.
func LookupID ¶
LookupID looks up the identifier corresponding to the given code. This function uses a read lock to ensure safe concurrent access to shared resources. Parameters: code - The integer value of the code to look up.
Returns: The string identifier corresponding to the code.
func MethodNotAllowed ¶
MethodNotAllowed generates a 405 error.
func NewCodeFormat ¶
NewCodeFormat generates an error for a given code
func RegisterCode ¶
RegisterCode register a new error code with the given ID,or overwriting any existing one
func RequestEntityTooLarge ¶
RequestEntityTooLarge generates a 413 error.
func TooManyRequests ¶
TooManyRequests generates a 429 error.
func Unauthorized ¶
Unauthorized generates a 401 error.
Types ¶
type Error ¶
type Error struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Code int32 `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"` Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` Detail string `protobuf:"bytes,4,opt,name=detail,proto3" json:"detail,omitempty"` // contains filtered or unexported fields }
func Parse ¶
Parse tries to parse a JSON string into an error. If that fails, it will set the given string as the error detail.
func (*Error) Descriptor
deprecated
func (*Error) GetMessage ¶ added in v0.0.7
func (*Error) ProtoMessage ¶
func (*Error) ProtoMessage()
func (*Error) ProtoReflect ¶
func (x *Error) ProtoReflect() protoreflect.Message
func (*Error) Validate ¶
Validate checks the field values on Error with the rules defined in the proto definition for this message. If any rules are violated, the first error encountered is returned, or nil if there are no violations.
func (*Error) ValidateAll ¶
ValidateAll checks the field values on Error with the rules defined in the proto definition for this message. If any rules are violated, the result is a list of violation errors wrapped in ErrorMultiError, or nil if none found.
type ErrorMultiError ¶
type ErrorMultiError []error
ErrorMultiError is an error wrapping multiple validation errors returned by Error.ValidateAll() if the designated constraints aren't met.
func (ErrorMultiError) AllErrors ¶
func (m ErrorMultiError) AllErrors() []error
AllErrors returns a list of validation violation errors.
func (ErrorMultiError) Error ¶
func (m ErrorMultiError) Error() string
Error returns a concatenation of all the error messages it wraps.
type ErrorValidationError ¶
type ErrorValidationError struct {
// contains filtered or unexported fields
}
ErrorValidationError is the validation error returned by Error.Validate if the designated constraints aren't met.
func (ErrorValidationError) Cause ¶
func (e ErrorValidationError) Cause() error
Cause function returns cause value.
func (ErrorValidationError) Error ¶
func (e ErrorValidationError) Error() string
Error satisfies the builtin error interface
func (ErrorValidationError) ErrorName ¶
func (e ErrorValidationError) ErrorName() string
ErrorName returns error name.
func (ErrorValidationError) Field ¶
func (e ErrorValidationError) Field() string
Field function returns field value.
func (ErrorValidationError) Key ¶
func (e ErrorValidationError) Key() bool
Key function returns key value.
func (ErrorValidationError) Reason ¶
func (e ErrorValidationError) Reason() string
Reason function returns reason value.
type MultiError ¶
type MultiError struct { Errors []*Error `protobuf:"bytes,1,rep,name=errors,proto3" json:"errors,omitempty"` // contains filtered or unexported fields }
func NewMultiError ¶
func NewMultiError() *MultiError
func (*MultiError) Append ¶
func (e *MultiError) Append(err *Error)
func (*MultiError) Descriptor
deprecated
func (*MultiError) Descriptor() ([]byte, []int)
Deprecated: Use MultiError.ProtoReflect.Descriptor instead.
func (*MultiError) Error ¶
func (e *MultiError) Error() string
func (*MultiError) GetErrors ¶
func (x *MultiError) GetErrors() []*Error
func (*MultiError) HasErrors ¶
func (e *MultiError) HasErrors() bool
func (*MultiError) ProtoMessage ¶
func (*MultiError) ProtoMessage()
func (*MultiError) ProtoReflect ¶
func (x *MultiError) ProtoReflect() protoreflect.Message
func (*MultiError) Reset ¶
func (x *MultiError) Reset()
func (*MultiError) String ¶
func (x *MultiError) String() string
func (*MultiError) Validate ¶
func (m *MultiError) Validate() error
Validate checks the field values on MultiError with the rules defined in the proto definition for this message. If any rules are violated, the first error encountered is returned, or nil if there are no violations.
func (*MultiError) ValidateAll ¶
func (m *MultiError) ValidateAll() error
ValidateAll checks the field values on MultiError with the rules defined in the proto definition for this message. If any rules are violated, the result is a list of violation errors wrapped in MultiErrorMultiError, or nil if none found.
type MultiErrorMultiError ¶
type MultiErrorMultiError []error
MultiErrorMultiError is an error wrapping multiple validation errors returned by MultiError.ValidateAll() if the designated constraints aren't met.
func (MultiErrorMultiError) AllErrors ¶
func (m MultiErrorMultiError) AllErrors() []error
AllErrors returns a list of validation violation errors.
func (MultiErrorMultiError) Error ¶
func (m MultiErrorMultiError) Error() string
Error returns a concatenation of all the error messages it wraps.
type MultiErrorValidationError ¶
type MultiErrorValidationError struct {
// contains filtered or unexported fields
}
MultiErrorValidationError is the validation error returned by MultiError.Validate if the designated constraints aren't met.
func (MultiErrorValidationError) Cause ¶
func (e MultiErrorValidationError) Cause() error
Cause function returns cause value.
func (MultiErrorValidationError) Error ¶
func (e MultiErrorValidationError) Error() string
Error satisfies the builtin error interface
func (MultiErrorValidationError) ErrorName ¶
func (e MultiErrorValidationError) ErrorName() string
ErrorName returns error name.
func (MultiErrorValidationError) Field ¶
func (e MultiErrorValidationError) Field() string
Field function returns field value.
func (MultiErrorValidationError) Key ¶
func (e MultiErrorValidationError) Key() bool
Key function returns key value.
func (MultiErrorValidationError) Reason ¶
func (e MultiErrorValidationError) Reason() string
Reason function returns reason value.