Documentation ¶
Index ¶
- Constants
- Variables
- type Details
- type Error
- func ErrInternal(msg string) *Error
- func ErrInvalidParameter(msg string) *Error
- func ErrNotFound(msg string) *Error
- func ErrUnauthorized(msg string) *Error
- func New(code, message string) *Error
- func NewWithLog(code, message, logMessage string) *Error
- func Newf(code, message string, args ...interface{}) *Error
- func NewfWithLog(code, message, logMessage string, args ...interface{}) *Error
- func Parse(err error) (*Error, bool)
- func ParseAndWrap(err error, msg string) *Error
- func Wrap(cause error, code, message string) *Error
- func WrapWithLog(cause error, code, message, logMessage string) *Error
- func Wrapf(cause error, code, message string, args ...interface{}) *Error
- func WrapfWithLog(cause error, code, message, logMessage string, args ...interface{}) *Error
- type Frame
- type StackTrace
Constants ¶
const ( // CodeInternal defines common internal error code CodeInternal = "common.internal" // CodeNotFound defines common not found error code CodeNotFound = "common.not_found" CodeUnauthorized = "common.unauthorized" // CodeInvalidParameter defines common invalid parameter error code CodeInvalidParameter = "common.invalid_parameter" // CodeTimeout defines common timeout error code CodeTimeout = "common.timeout" // CodeAlreadyExists defines common entity already exists error code CodeAlreadyExists = "common.already_exist" // CodeForbidden defines common forbidden access error code CodeForbidden = "common.forbidden" // CodeUnimplemented defines common forbidden access error code CodeUnimplemented = "common.unimplemented" )
Variables ¶
var DefaultCodeMap = map[codes.Code]string{ codes.Canceled: CodeTimeout, codes.Unknown: CodeInternal, codes.InvalidArgument: CodeInvalidParameter, codes.DeadlineExceeded: CodeTimeout, codes.NotFound: CodeNotFound, codes.AlreadyExists: CodeAlreadyExists, codes.PermissionDenied: CodeForbidden, codes.ResourceExhausted: CodeInternal, codes.FailedPrecondition: CodeInternal, codes.Aborted: CodeInternal, codes.OutOfRange: CodeInternal, codes.Unimplemented: CodeUnimplemented, codes.Internal: CodeInternal, codes.Unavailable: CodeInternal, codes.DataLoss: CodeInternal, codes.Unauthenticated: CodeUnauthorized, }
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct { Code string `json:"code"` Message string `json:"message"` Details []*Details `json:"details"` // contains filtered or unexported fields }
Error defines standard error of gogox
Code is intended to be a unique identifier of each gogox error. You should use Code to determine your error handling. Message is intended to be a user-friendly error message. Details is intended to store additional information about the error, commonly used for 4xx or user induced error (such as invalid parameter). logMessage is intended to store log error message, typically contains more sensitive information that is needed by end user. DO NOT use logMessage for API response
func ErrInternal ¶ added in v0.2.0
ErrInternal returns generic gogox error with CodeInternal
func ErrInvalidParameter ¶ added in v0.2.0
ErrInvalidParameter returns generic gogox error with CodeInvalidParameter
func ErrNotFound ¶ added in v0.2.0
ErrNotFound returns generic gogox error with CodeNotFound
func ErrUnauthorized ¶ added in v0.2.0
ErrUnauthorized returns generic gogox error with CodeUnauthorized
func New ¶
New creates new gogox's error logMessage is automatically built from code and message stack is populated in each initialization
func NewWithLog ¶
NewWithLog creates new gogox's error with overriden logMessage
func NewfWithLog ¶
NewfWithLog creates new gogox's error with overriden logMessage and message formatting
func ParseAndWrap ¶ added in v0.2.0
ParseAndWrap provides sugar syntax for parsing err to Error instance. if the parsing fail, automatically wrap the error into internal error with msg. if the parsing successful, return the original error.
func WrapWithLog ¶
WrapWithLog create new gogox's error with cause and log message
func WrapfWithLog ¶
WrapfWithLog create new gogox's error with cause, logMessage and message formatting
func (*Error) AddDetails ¶
AddDetails add error details
func (*Error) LogError ¶
LogError returns message for debugging, concating cause(s)'s logMessage if any.
func (*Error) PrintStackTrace ¶
PrintStackTrace prints stack trace from error stack.
type Frame ¶
type Frame uintptr
Frame represents a program counter inside a stack frame. For historical reasons if Frame is interpreted as a uintptr its value represents the program counter + 1.
type StackTrace ¶
type StackTrace []Frame
StackTrace is stack of Frames from innermost (newest) to outermost (oldest).