errors

package
v0.0.0-...-4c9bff6 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidInput       = &Exception{Code: 400001, Message: "One of the request inputs is not valid.", Status: http.StatusBadRequest, GRPCCode: codes.InvalidArgument}
	ErrInvalidHeaderValue = &Exception{Code: 400003, Message: "The value provided for one of the HTTP headers was not in the correct format.", Status: http.StatusBadRequest, GRPCCode: codes.InvalidArgument}
	ErrUnauthorized       = &Exception{Code: 401001, Message: "The request unauthorized", Status: http.StatusUnauthorized, GRPCCode: codes.PermissionDenied}
	ErrForbidden          = &Exception{Code: 403001, Message: "Forbidden.", Status: http.StatusForbidden, GRPCCode: codes.PermissionDenied}
	ErrPageNotFound       = &Exception{Code: 404001, Message: "Page not found.", Status: http.StatusNotFound, GRPCCode: codes.NotFound}
	ErrResourceNotFound   = &Exception{Code: 404002, Message: "The specified resource does not exist.", Status: http.StatusNotFound}
	ErrConflict           = &Exception{Code: 409001, Message: "The request conflict.", Status: http.StatusConflict, GRPCCode: codes.AlreadyExists}
	ErrTooManyRequests    = &Exception{Code: 429001, Message: "Too Many Requests", Status: http.StatusTooManyRequests, GRPCCode: codes.PermissionDenied}
	ErrInternal           = &Exception{Code: 500001, Message: "Serve occur error.", Status: http.StatusInternalServerError, GRPCCode: codes.Internal}
)

Functions

func As

func As(err error, target interface{}) bool

func Cause

func Cause(target error) error

func ErrorResponse

func ErrorResponse(ctx context.Context, err error, w http.ResponseWriter)

ErrorResponse error response for go-kit

func Is

func Is(err error, target error) bool

Is Check input is same

func WithMessage

func WithMessage(err error, message string) error

WithMessage annotates err with a new message. If err is nil, WithMessage returns nil.

func WithMessagef

func WithMessagef(err error, format string, args ...interface{}) error

WithMessagef annotates err with the format specifier. If err is nil, WithMessagef returns nil.

func Wrap

func Wrap(err error, msg string) error

Wrap returns an error annotating err with a stack trace at the point Wrap is called, and the supplied message. If err is nil, Wrap returns nil.

func Wrapf

func Wrapf(err error, format string, args ...interface{}) error

Wrapf returns an error annotating err with a stack trace at the point Wrapf is called, and the format specifier. If err is nil, Wrapf returns nil.

Types

type Detail

type Detail struct {
	Type     string                 `json:"@type,omitempty"`
	Reason   string                 `json:"reason,omitempty"`
	Domain   string                 `json:"domain,omitempty"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

type DetailData

type DetailData map[string]interface{}

DetailData is metadata for client debug

type Exception

type Exception struct {
	Code     int        `json:"code"`              // error code for client define how to handle error
	Status   int        `json:"status"`            // status is http status
	Message  string     `json:"message"`           // error message for client
	GRPCCode codes.Code `json:"grpc_code"`         //  grpc error code
	Details  []Detail   `json:"details,omitempty"` // details is metadata for client debug
}

Exception define custom error for tracmo cloud

func New

func New(message string) *Exception

New server internal error with message

func TryConvert

func TryConvert(target error) *Exception

func (*Exception) Error

func (e *Exception) Error() string

Error implement golang error

func (*Exception) ToViewModel

func (e *Exception) ToViewModel() (int, *View)

ToViewModel to restful view

func (*Exception) WithDetails

func (e *Exception) WithDetails(details ...Detail) *Exception

WithDetails set detail error message

type LoggerErrorHandle

type LoggerErrorHandle struct {
}

func NewLoggingErrorHandle

func NewLoggingErrorHandle() *LoggerErrorHandle

func (*LoggerErrorHandle) Handle

func (h *LoggerErrorHandle) Handle(ctx context.Context, err error)

type View

type View struct {
	Code    int      `json:"code"`
	Info    string   `json:"info"`
	Details []Detail `json:"details,omitempty"`
}

Jump to

Keyboard shortcuts

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