Documentation ¶
Index ¶
- Constants
- func CorrelationID(err error) string
- func GRPCCode(err error) codes.Code
- func GRPCMessage(err error) string
- func HTTPStatusFromRPC(c codes.Code) int
- func IsInvalidModel(err error) bool
- func IsInvalidRequestError(err error) bool
- func IsSQLNotFoundError(err error) bool
- func IsTimeout(err error) bool
- func Status(err error) int
- type Error
- func AccountNotFound(msgFormat string, vals ...interface{}) *Error
- func BadNonce(msgFormat string, vals ...interface{}) *Error
- func Conflict(msgFormat string, vals ...interface{}) *Error
- func ContentLengthRequired() *Error
- func FailedToReadRequestBody(msgFormat string, vals ...interface{}) *Error
- func Forbidden(msgFormat string, vals ...interface{}) *Error
- func FromOAuth(code, descr string) *Error
- func InvalidContentType(msgFormat string, vals ...interface{}) *Error
- func InvalidJSON(msgFormat string, vals ...interface{}) *Error
- func InvalidParam(msgFormat string, vals ...interface{}) *Error
- func InvalidRequest(msgFormat string, vals ...interface{}) *Error
- func Malformed(msgFormat string, vals ...interface{}) *Error
- func New(status int, code string, msgFormat string, vals ...interface{}) *Error
- func NewFromCtx(ctx context.Context, status int, code string, msgFormat string, ...) *Error
- func NewFromPb(err error) *Error
- func NewGrpc(code codes.Code, msgFormat string, vals ...interface{}) *Error
- func NewGrpcFromCtx(ctx context.Context, code codes.Code, msgFormat string, vals ...interface{}) *Error
- func NotFound(msgFormat string, vals ...interface{}) *Error
- func NotReady(msgFormat string, vals ...interface{}) *Error
- func RateLimitExceeded(msgFormat string, vals ...interface{}) *Error
- func RequestTooLarge(msgFormat string, vals ...interface{}) *Error
- func Timeout(msgFormat string, vals ...interface{}) *Error
- func TooEarly(msgFormat string, vals ...interface{}) *Error
- func Unauthorized(msgFormat string, vals ...interface{}) *Error
- func Unexpected(msgFormat string, vals ...interface{}) *Error
- func Wrap(err error, msgAndArgs ...any) *Error
- func WrapWithCtx(ctx context.Context, err error, msgAndArgs ...any) *Error
- func (e *Error) Cause() error
- func (e *Error) CorrelationID() string
- func (e *Error) Error() string
- func (e *Error) GRPCStatus() *status.Status
- func (e *Error) Is(target error) bool
- func (e *Error) Unwrap() error
- func (e *Error) WithCause(err error) *Error
- func (e *Error) WithContext(ctx context.Context) *Error
- func (e *Error) WriteHTTPResponse(w http.ResponseWriter, r *http.Request)
- type ManyError
- func (m *ManyError) Add(key string, err error) *ManyError
- func (m *ManyError) Cause() error
- func (m *ManyError) CorrelationID() string
- func (m *ManyError) Error() string
- func (m *ManyError) GRPCStatus() *status.Status
- func (m *ManyError) HasErrors() bool
- func (m *ManyError) WithCause(err error) *ManyError
- func (m *ManyError) WriteHTTPResponse(w http.ResponseWriter, r *http.Request)
Constants ¶
const ( // CodeAccountNotFound when requested account not found CodeAccountNotFound = "account_not_found" // CodeBadNonce is returned for bad nonce. CodeBadNonce = "bad_nonce" // CodeConflict is returned whith 409 CONFLICT response code. CodeConflict = "conflict" // CodeConnection is returned when connection failed. CodeConnection = "connection" // CodeContentLengthRequired is returned when request does not specify ContentLength. CodeContentLengthRequired = "content_length_required" // CodeFailedToReadRequestBody is returned when there's an error reading the HTTP body of the request. CodeFailedToReadRequestBody = "request_body" // CodeForbidden is returned when the client is not authorized to access the resource indicated. CodeForbidden = "forbidden" // CodeInvalidContentType is returned when request specifies invalid Content-Type. CodeInvalidContentType = "invalid_content_type" // CodeInvalidJSON is returned when we were unable to parse a client supplied JSON Payload. CodeInvalidJSON = "invalid_json" // CodeInvalidParam is returned where a URL parameter, or other type of generalized parameters value is invalid. CodeInvalidParam = "invalid_parameter" // CodeInvalidRequest is returned when the request validation failed. CodeInvalidRequest = "invalid_request" // CodeMalformed is returned when the request was malformed. CodeMalformed = "malformed" // CodeNotFound is returned when the requested URL doesn't exist. CodeNotFound = "not_found" // CodeNotReady is returned when the service is not ready to serve CodeNotReady = "not_ready" // CodeRateLimitExceeded is returned when the client has exceeded their request allotment. CodeRateLimitExceeded = "rate_limit_exceeded" // CodeRequestFailed is returned when an outbound request failed. CodeRequestFailed = "request_failed" // CodeRequestTooLarge is returned when the client provided payload is larger than allowed for the particular resource. CodeRequestTooLarge = "request_too_large" // CodeTimeout is returned when request timed out. CodeTimeout = "timeout" // CodeTooEarly is returned when the client makes requests too early. CodeTooEarly = "too_early" CodeUnauthorized = "unauthorized" // CodeUnexpected is returned when something went wrong. CodeUnexpected = "unexpected" )
Variables ¶
This section is empty.
Functions ¶
func CorrelationID ¶
CorrelationID returns correlation ID from GRPC error
func HTTPStatusFromRPC ¶
HTTPStatusFromRPC returns HTTP status
func IsInvalidModel ¶
IsInvalidModel returns true, if error is InvalidModel
func IsInvalidRequestError ¶
IsInvalidRequestError returns true for Invalid request error
func IsSQLNotFoundError ¶
IsSQLNotFoundError returns true, if error is NotFound
Types ¶
type Error ¶
type Error struct { // HTTPStatus contains the HTTP status code that should be used for this error HTTPStatus int `json:"-"` RPCStatus codes.Code `json:"-"` // Code identifies the particular error condition [for programatic consumers] Code string `json:"code"` // RequestID identifies the request ID RequestID string `json:"request_id,omitempty"` // Message is an textual description of the error Message string `json:"message"` // contains filtered or unexported fields }
Error represents a single error from API.
func AccountNotFound ¶
AccountNotFound returns Error instance with AccountNotFound code
func ContentLengthRequired ¶
func ContentLengthRequired() *Error
ContentLengthRequired returns Error instance with ContentLengthRequired code
func FailedToReadRequestBody ¶
FailedToReadRequestBody returns Error instance with FailedToReadRequestBody code
func InvalidContentType ¶
InvalidContentType returns Error instance with InvalidContentType code
func InvalidJSON ¶
InvalidJSON returns Error instance with InvalidJSON code
func InvalidParam ¶
InvalidParam returns Error instance with InvalidParam code
func InvalidRequest ¶
InvalidRequest returns Error instance with InvalidRequest code
func NewFromCtx ¶
func NewFromCtx(ctx context.Context, status int, code string, msgFormat string, vals ...interface{}) *Error
NewFromCtx returns Error instance, building the message string along the way
func NewGrpcFromCtx ¶
func NewGrpcFromCtx(ctx context.Context, code codes.Code, msgFormat string, vals ...interface{}) *Error
NewGrpcFromCtx returns new GRPC error
func RateLimitExceeded ¶
RateLimitExceeded returns Error instance with RateLimitExceeded code
func RequestTooLarge ¶
RequestTooLarge returns Error instance with RequestTooLarge code
func Unauthorized ¶
Unauthorized returns Error instance with Unauthorized code
func Unexpected ¶
Unexpected returns Error instance with Unexpected code
func Wrap ¶
Wrap returns Error instance with NotFound, Timeout or Internal code, depending on the error from DB
func WrapWithCtx ¶
WrapWithCtx returns wrapped Error with Context
func (*Error) CorrelationID ¶
CorrelationID implements the Correlation interface, and returns request ID
func (*Error) GRPCStatus ¶
GRPCStatus returns gRPC status
func (*Error) Is ¶
Is implements future error.Is functionality. A Error is equivalent if the code and message are identical.
func (*Error) WithContext ¶
WithContext adds the context
func (*Error) WriteHTTPResponse ¶
func (e *Error) WriteHTTPResponse(w http.ResponseWriter, r *http.Request)
WriteHTTPResponse implements how to serialize this error into a HTTP Response
type ManyError ¶
type ManyError struct { // HTTPStatus contains the HTTP status code that should be used for this error HTTPStatus int `json:"-"` RPCStatus codes.Code `json:"-"` // Code identifies the particular error condition [for programatic consumers] Code string `json:"code,omitempty"` // RequestID identifies the request ID RequestID string `json:"request_id,omitempty"` // Message is an textual description of the error Message string `json:"message,omitempty"` Errors map[string]*Error `json:"errors,omitempty"` // contains filtered or unexported fields }
ManyError identifies many errors from API.
func (*ManyError) CorrelationID ¶
CorrelationID implements the Correlation interface, and returns request ID
func (*ManyError) GRPCStatus ¶
GRPCStatus returns gRPC status
func (*ManyError) WriteHTTPResponse ¶
func (m *ManyError) WriteHTTPResponse(w http.ResponseWriter, r *http.Request)
WriteHTTPResponse implements how to serialize this error into a HTTP Response