errorpkg

package
v0.2.16 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 12 Imported by: 28

README

error

基于 github.com/pkg/errors


kratos proto client kratos/error/error.kit.proto

Documentation

Index

Examples

Constants

View Source
const EnumNumberKey = "enum_number"

Variables

View Source
var (
	ERROR_name = map[int32]string{
		0:     "UNKNOWN",
		10001: "REQUEST_FAILED",
		10002: "RECORD_NOT_FOUND",
		10003: "RECORD_ALREADY_EXISTS",
		10004: "NETWORK_ERROR",
		10005: "NETWORK_TIMEOUT",
		10006: "CONNECTION_ERROR",
		10007: "UNINITIALIZED",
		10008: "UNIMPLEMENTED",
		10009: "INVALID_PARAMETER",
		10010: "REQUEST_NOT_SUPPORT",
		10011: "INTERNAL_ERROR",
		10012: "PANIC",
		10013: "FATAL",
		11001: "DB",
		11002: "MYSQL",
		11003: "MONGO",
		11004: "CACHE",
		11005: "REDIS",
		12001: "MQ",
		12002: "QUEUE",
		12003: "RABBIT_MQ",
		12004: "KAFKA",
		13002: "THIRD_PARTY_SERVICE_INVALID_CODE",
		13001: "THIRD_PARTY_SERVICE_INTERNAL_ERROR",
		100:   "CONTINUE",
		101:   "SWITCHING_PROTOCOLS",
		102:   "PROCESSING",
		103:   "EARLY_HINTS",
		200:   "OK",
		201:   "CREATED",
		202:   "ACCEPTED",
		203:   "NON_AUTHORITATIVE_INFO",
		204:   "NO_CONTENT",
		205:   "RESET_CONTENT",
		206:   "PARTIAL_CONTENT",
		207:   "MULTI_STATUS",
		208:   "ALREADY_REPORTED",
		226:   "I_M_USED",
		300:   "MULTIPLE_CHOICES",
		301:   "MOVED_PERMANENTLY",
		302:   "FOUND",
		303:   "SEE_OTHER",
		304:   "NOT_MODIFIED",
		305:   "USE_PROXY",
		306:   "EMPTY306",
		307:   "TEMPORARY_REDIRECT",
		308:   "PERMANENT_REDIRECT",
		400:   "BAD_REQUEST",
		401:   "UNAUTHORIZED",
		402:   "PAYMENT_REQUIRED",
		403:   "FORBIDDEN",
		404:   "NOT_FOUND",
		405:   "METHOD_NOT_ALLOWED",
		406:   "NOT_ACCEPTABLE",
		407:   "PROXY_AUTH_REQUIRED",
		408:   "REQUEST_TIMEOUT",
		409:   "CONFLICT",
		410:   "GONE",
		411:   "LENGTH_REQUIRED",
		412:   "PRECONDITION_FAILED",
		413:   "REQUEST_ENTITY_TOO_LARGE",
		414:   "REQUEST_URI_TOO_LONG",
		415:   "UNSUPPORTED_MEDIA_TYPE",
		416:   "REQUESTED_RANGE_NOT_SATISFIABLE",
		417:   "EXPECTATION_FAILED",
		418:   "TEAPOT",
		421:   "MISDIRECTED_REQUEST",
		422:   "UNPROCESSABLE_ENTITY",
		423:   "LOCKED",
		424:   "FAILED_DEPENDENCY",
		425:   "TOO_EARLY",
		426:   "UPGRADE_REQUIRED",
		428:   "PRECONDITION_REQUIRED",
		429:   "TOO_MANY_REQUESTS",
		431:   "REQUEST_HEADER_FIELDS_TOO_LARGE",
		451:   "UNAVAILABLE_FOR_LEGAL_REASONS",
		499:   "CLIENT_CLOSE",
		500:   "INTERNAL_SERVER",
		501:   "NOT_IMPLEMENTED",
		502:   "BAD_GATEWAY",
		503:   "SERVICE_UNAVAILABLE",
		504:   "GATEWAY_TIMEOUT",
		505:   "HTTP_VERSION_NOT_SUPPORTED",
		506:   "VARIANT_ALSO_NEGOTIATES",
		507:   "INSUFFICIENT_STORAGE",
		508:   "LOOP_DETECTED",
		510:   "NOT_EXTENDED",
		511:   "NETWORK_AUTHENTICATION_REQUIRED",
	}
	ERROR_value = map[string]int32{
		"UNKNOWN":                            0,
		"REQUEST_FAILED":                     10001,
		"RECORD_NOT_FOUND":                   10002,
		"RECORD_ALREADY_EXISTS":              10003,
		"NETWORK_ERROR":                      10004,
		"NETWORK_TIMEOUT":                    10005,
		"CONNECTION_ERROR":                   10006,
		"UNINITIALIZED":                      10007,
		"UNIMPLEMENTED":                      10008,
		"INVALID_PARAMETER":                  10009,
		"REQUEST_NOT_SUPPORT":                10010,
		"INTERNAL_ERROR":                     10011,
		"PANIC":                              10012,
		"FATAL":                              10013,
		"DB":                                 11001,
		"MYSQL":                              11002,
		"MONGO":                              11003,
		"CACHE":                              11004,
		"REDIS":                              11005,
		"MQ":                                 12001,
		"QUEUE":                              12002,
		"RABBIT_MQ":                          12003,
		"KAFKA":                              12004,
		"THIRD_PARTY_SERVICE_INVALID_CODE":   13002,
		"THIRD_PARTY_SERVICE_INTERNAL_ERROR": 13001,
		"CONTINUE":                           100,
		"SWITCHING_PROTOCOLS":                101,
		"PROCESSING":                         102,
		"EARLY_HINTS":                        103,
		"OK":                                 200,
		"CREATED":                            201,
		"ACCEPTED":                           202,
		"NON_AUTHORITATIVE_INFO":             203,
		"NO_CONTENT":                         204,
		"RESET_CONTENT":                      205,
		"PARTIAL_CONTENT":                    206,
		"MULTI_STATUS":                       207,
		"ALREADY_REPORTED":                   208,
		"I_M_USED":                           226,
		"MULTIPLE_CHOICES":                   300,
		"MOVED_PERMANENTLY":                  301,
		"FOUND":                              302,
		"SEE_OTHER":                          303,
		"NOT_MODIFIED":                       304,
		"USE_PROXY":                          305,
		"EMPTY306":                           306,
		"TEMPORARY_REDIRECT":                 307,
		"PERMANENT_REDIRECT":                 308,
		"BAD_REQUEST":                        400,
		"UNAUTHORIZED":                       401,
		"PAYMENT_REQUIRED":                   402,
		"FORBIDDEN":                          403,
		"NOT_FOUND":                          404,
		"METHOD_NOT_ALLOWED":                 405,
		"NOT_ACCEPTABLE":                     406,
		"PROXY_AUTH_REQUIRED":                407,
		"REQUEST_TIMEOUT":                    408,
		"CONFLICT":                           409,
		"GONE":                               410,
		"LENGTH_REQUIRED":                    411,
		"PRECONDITION_FAILED":                412,
		"REQUEST_ENTITY_TOO_LARGE":           413,
		"REQUEST_URI_TOO_LONG":               414,
		"UNSUPPORTED_MEDIA_TYPE":             415,
		"REQUESTED_RANGE_NOT_SATISFIABLE":    416,
		"EXPECTATION_FAILED":                 417,
		"TEAPOT":                             418,
		"MISDIRECTED_REQUEST":                421,
		"UNPROCESSABLE_ENTITY":               422,
		"LOCKED":                             423,
		"FAILED_DEPENDENCY":                  424,
		"TOO_EARLY":                          425,
		"UPGRADE_REQUIRED":                   426,
		"PRECONDITION_REQUIRED":              428,
		"TOO_MANY_REQUESTS":                  429,
		"REQUEST_HEADER_FIELDS_TOO_LARGE":    431,
		"UNAVAILABLE_FOR_LEGAL_REASONS":      451,
		"CLIENT_CLOSE":                       499,
		"INTERNAL_SERVER":                    500,
		"NOT_IMPLEMENTED":                    501,
		"BAD_GATEWAY":                        502,
		"SERVICE_UNAVAILABLE":                503,
		"GATEWAY_TIMEOUT":                    504,
		"HTTP_VERSION_NOT_SUPPORTED":         505,
		"VARIANT_ALSO_NEGOTIATES":            506,
		"INSUFFICIENT_STORAGE":               507,
		"LOOP_DETECTED":                      508,
		"NOT_EXTENDED":                       510,
		"NETWORK_AUTHENTICATION_REQUIRED":    511,
	}
)

Enum value maps for ERROR.

View Source
var (
	// DefaultStackTracerDepth 错误追踪最深层数
	DefaultStackTracerDepth = 10
)
View Source
var File_kratos_error_error_kit_proto protoreflect.FileDescriptor

Functions

func BadRequest

func BadRequest(reason, message string, eSlice ...error) *errors.Error

BadRequest mapped to a 400 response.

func BadRequestWithMetadata

func BadRequestWithMetadata(reason, message string, md map[string]string) *errors.Error

BadRequestWithMetadata mapped to a 400 response.

func Caller

func Caller(err error) (callers []string)

Caller 序列化调用者:file:line

func CallerWithSkip

func CallerWithSkip(err error, skip int) (callers []string)

CallerWithSkip 序列化调用者:file:line

func Cause

func Cause(err error) error

Cause returns the underlying cause of the error

Example
err := New(http.StatusNotFound, "StatusNotFound", "StatusNotFound")
fmt.Println(Cause(err))
Output:

func ClientClosed

func ClientClosed(reason, message string, eSlice ...error) *errors.Error

ClientClosed mapped to a HTTP 499 response.

func ClientClosedWithMetadata

func ClientClosedWithMetadata(reason, message string, md map[string]string) *errors.Error

ClientClosedWithMetadata mapped to a HTTP 499 response.

func Code

func Code(err error) int

Code returns the http code for a error.

Example
err := New(http.StatusNotFound, "StatusNotFound", "StatusNotFound")
fmt.Println(Code(err))
Output:

func Conflict

func Conflict(reason, message string, eSlice ...error) *errors.Error

Conflict mapped to a 409 response.

func ConflictWithMetadata

func ConflictWithMetadata(reason, message string, md map[string]string) *errors.Error

ConflictWithMetadata mapped to a 409 response.

func ErrMessage

func ErrMessage(key string) string

ErrMessage ...

func ErrorAccepted

func ErrorAccepted(format string, args ...interface{}) *errors.Error

func ErrorAlreadyReported

func ErrorAlreadyReported(format string, args ...interface{}) *errors.Error

func ErrorBadGateway

func ErrorBadGateway(format string, args ...interface{}) *errors.Error

func ErrorBadRequest

func ErrorBadRequest(format string, args ...interface{}) *errors.Error

BAD_REQUEST Bad Request

func ErrorCache

func ErrorCache(format string, args ...interface{}) *errors.Error

func ErrorClientClose

func ErrorClientClose(format string, args ...interface{}) *errors.Error

func ErrorConflict

func ErrorConflict(format string, args ...interface{}) *errors.Error

func ErrorConnectionError

func ErrorConnectionError(format string, args ...interface{}) *errors.Error

func ErrorContinue

func ErrorContinue(format string, args ...interface{}) *errors.Error

CONTINUE Continue

func ErrorCreated

func ErrorCreated(format string, args ...interface{}) *errors.Error

func ErrorDb

func ErrorDb(format string, args ...interface{}) *errors.Error

DB database

func ErrorEarlyHints

func ErrorEarlyHints(format string, args ...interface{}) *errors.Error

func ErrorEmpty306

func ErrorEmpty306(format string, args ...interface{}) *errors.Error

func ErrorExpectationFailed

func ErrorExpectationFailed(format string, args ...interface{}) *errors.Error

func ErrorFailedDependency

func ErrorFailedDependency(format string, args ...interface{}) *errors.Error

func ErrorFatal

func ErrorFatal(format string, args ...interface{}) *errors.Error

func ErrorForbidden

func ErrorForbidden(format string, args ...interface{}) *errors.Error

func ErrorFound

func ErrorFound(format string, args ...interface{}) *errors.Error

func ErrorGatewayTimeout

func ErrorGatewayTimeout(format string, args ...interface{}) *errors.Error

func ErrorGone

func ErrorGone(format string, args ...interface{}) *errors.Error

func ErrorHttpVersionNotSupported

func ErrorHttpVersionNotSupported(format string, args ...interface{}) *errors.Error

func ErrorIMUsed

func ErrorIMUsed(format string, args ...interface{}) *errors.Error

func ErrorInsufficientStorage

func ErrorInsufficientStorage(format string, args ...interface{}) *errors.Error

func ErrorInternalError

func ErrorInternalError(format string, args ...interface{}) *errors.Error

func ErrorInternalServer

func ErrorInternalServer(format string, args ...interface{}) *errors.Error

INTERNAL_SERVER Internal Server Error

func ErrorInvalidParameter

func ErrorInvalidParameter(format string, args ...interface{}) *errors.Error

func ErrorKafka

func ErrorKafka(format string, args ...interface{}) *errors.Error

func ErrorLengthRequired

func ErrorLengthRequired(format string, args ...interface{}) *errors.Error

func ErrorLocked

func ErrorLocked(format string, args ...interface{}) *errors.Error

func ErrorLoopDetected

func ErrorLoopDetected(format string, args ...interface{}) *errors.Error

func ErrorMethodNotAllowed

func ErrorMethodNotAllowed(format string, args ...interface{}) *errors.Error

func ErrorMisdirectedRequest

func ErrorMisdirectedRequest(format string, args ...interface{}) *errors.Error

func ErrorMongo

func ErrorMongo(format string, args ...interface{}) *errors.Error

func ErrorMovedPermanently

func ErrorMovedPermanently(format string, args ...interface{}) *errors.Error

func ErrorMq

func ErrorMq(format string, args ...interface{}) *errors.Error

MQ message queue

func ErrorMultiStatus

func ErrorMultiStatus(format string, args ...interface{}) *errors.Error

func ErrorMultipleChoices

func ErrorMultipleChoices(format string, args ...interface{}) *errors.Error

MULTIPLE_CHOICES MultipleChoices

func ErrorMysql

func ErrorMysql(format string, args ...interface{}) *errors.Error

func ErrorNetworkAuthenticationRequired

func ErrorNetworkAuthenticationRequired(format string, args ...interface{}) *errors.Error

func ErrorNetworkError

func ErrorNetworkError(format string, args ...interface{}) *errors.Error

func ErrorNetworkTimeout

func ErrorNetworkTimeout(format string, args ...interface{}) *errors.Error

func ErrorNoContent

func ErrorNoContent(format string, args ...interface{}) *errors.Error

func ErrorNonAuthoritativeInfo

func ErrorNonAuthoritativeInfo(format string, args ...interface{}) *errors.Error

func ErrorNotAcceptable

func ErrorNotAcceptable(format string, args ...interface{}) *errors.Error

func ErrorNotExtended

func ErrorNotExtended(format string, args ...interface{}) *errors.Error

func ErrorNotFound

func ErrorNotFound(format string, args ...interface{}) *errors.Error

func ErrorNotImplemented

func ErrorNotImplemented(format string, args ...interface{}) *errors.Error

func ErrorNotModified

func ErrorNotModified(format string, args ...interface{}) *errors.Error

func ErrorOk

func ErrorOk(format string, args ...interface{}) *errors.Error

OK OK

func ErrorPanic

func ErrorPanic(format string, args ...interface{}) *errors.Error

func ErrorPartialContent

func ErrorPartialContent(format string, args ...interface{}) *errors.Error

func ErrorPaymentRequired

func ErrorPaymentRequired(format string, args ...interface{}) *errors.Error

func ErrorPermanentRedirect

func ErrorPermanentRedirect(format string, args ...interface{}) *errors.Error

func ErrorPreconditionFailed

func ErrorPreconditionFailed(format string, args ...interface{}) *errors.Error

func ErrorPreconditionRequired

func ErrorPreconditionRequired(format string, args ...interface{}) *errors.Error

func ErrorProcessing

func ErrorProcessing(format string, args ...interface{}) *errors.Error

func ErrorProxyAuthRequired

func ErrorProxyAuthRequired(format string, args ...interface{}) *errors.Error

func ErrorQueue

func ErrorQueue(format string, args ...interface{}) *errors.Error

func ErrorRabbitMq

func ErrorRabbitMq(format string, args ...interface{}) *errors.Error

func ErrorRecordAlreadyExists

func ErrorRecordAlreadyExists(format string, args ...interface{}) *errors.Error

func ErrorRecordNotFound

func ErrorRecordNotFound(format string, args ...interface{}) *errors.Error

func ErrorRedis

func ErrorRedis(format string, args ...interface{}) *errors.Error

func ErrorRequestEntityTooLarge

func ErrorRequestEntityTooLarge(format string, args ...interface{}) *errors.Error

func ErrorRequestFailed

func ErrorRequestFailed(format string, args ...interface{}) *errors.Error

func ErrorRequestHeaderFieldsTooLarge

func ErrorRequestHeaderFieldsTooLarge(format string, args ...interface{}) *errors.Error

func ErrorRequestNotSupport

func ErrorRequestNotSupport(format string, args ...interface{}) *errors.Error

func ErrorRequestTimeout

func ErrorRequestTimeout(format string, args ...interface{}) *errors.Error

func ErrorRequestUriTooLong

func ErrorRequestUriTooLong(format string, args ...interface{}) *errors.Error

func ErrorRequestedRangeNotSatisfiable

func ErrorRequestedRangeNotSatisfiable(format string, args ...interface{}) *errors.Error

func ErrorResetContent

func ErrorResetContent(format string, args ...interface{}) *errors.Error

func ErrorSeeOther

func ErrorSeeOther(format string, args ...interface{}) *errors.Error

func ErrorServiceUnavailable

func ErrorServiceUnavailable(format string, args ...interface{}) *errors.Error

func ErrorSwitchingProtocols

func ErrorSwitchingProtocols(format string, args ...interface{}) *errors.Error

func ErrorTeapot

func ErrorTeapot(format string, args ...interface{}) *errors.Error

func ErrorTemporaryRedirect

func ErrorTemporaryRedirect(format string, args ...interface{}) *errors.Error

func ErrorThirdPartyServiceInternalError

func ErrorThirdPartyServiceInternalError(format string, args ...interface{}) *errors.Error

第三方服务错误

func ErrorThirdPartyServiceInvalidCode

func ErrorThirdPartyServiceInvalidCode(format string, args ...interface{}) *errors.Error

THIRD_PARTY_SERVICE_INVALID_CODE third party

func ErrorTooEarly

func ErrorTooEarly(format string, args ...interface{}) *errors.Error

func ErrorTooManyRequests

func ErrorTooManyRequests(format string, args ...interface{}) *errors.Error

func ErrorUnauthorized

func ErrorUnauthorized(format string, args ...interface{}) *errors.Error

func ErrorUnavailableForLegalReasons

func ErrorUnavailableForLegalReasons(format string, args ...interface{}) *errors.Error

func ErrorUnimplemented

func ErrorUnimplemented(format string, args ...interface{}) *errors.Error

func ErrorUninitialized

func ErrorUninitialized(format string, args ...interface{}) *errors.Error

func ErrorUnknown

func ErrorUnknown(format string, args ...interface{}) *errors.Error

UNKNOWN 常规

func ErrorUnprocessableEntity

func ErrorUnprocessableEntity(format string, args ...interface{}) *errors.Error

func ErrorUnsupportedMediaType

func ErrorUnsupportedMediaType(format string, args ...interface{}) *errors.Error

func ErrorUpgradeRequired

func ErrorUpgradeRequired(format string, args ...interface{}) *errors.Error

func ErrorUseProxy

func ErrorUseProxy(format string, args ...interface{}) *errors.Error

func ErrorVariantAlsoNegotiates

func ErrorVariantAlsoNegotiates(format string, args ...interface{}) *errors.Error

func Forbidden

func Forbidden(reason, message string, eSlice ...error) *errors.Error

Forbidden mapped to a 403 response.

func ForbiddenWithMetadata

func ForbiddenWithMetadata(reason, message string, md map[string]string) *errors.Error

ForbiddenWithMetadata mapped to a 403 response.

func FromError

func FromError(err error) *errors.Error

FromError try to convert an error to *errors.Error

Example
err := New(http.StatusNotFound, "StatusNotFound", "StatusNotFound")
cause := FromError(err)
fmt.Println("error Code ", cause.Code)
fmt.Println("error Reason ", cause.Reason)
fmt.Println("error Message ", cause.Message)
fmt.Println("error Metadata ", cause.Metadata)
Output:

func GatewayTimeout

func GatewayTimeout(reason, message string, eSlice ...error) *errors.Error

GatewayTimeout mapped to a HTTP 504 response.

func GatewayTimeoutWithMetadata

func GatewayTimeoutWithMetadata(reason, message string, md map[string]string) *errors.Error

GatewayTimeoutWithMetadata mapped to a HTTP 504 response.

func InternalServer

func InternalServer(reason, message string, eSlice ...error) *errors.Error

InternalServer mapped to a 500 response.

func InternalServerWithMetadata

func InternalServerWithMetadata(reason, message string, md map[string]string) *errors.Error

InternalServerWithMetadata mapped to a 500 response.

func Is

func Is(err, target error) bool

Is ...

func IsAccepted

func IsAccepted(err error) bool

func IsAlreadyReported

func IsAlreadyReported(err error) bool

func IsBadGateway

func IsBadGateway(err error) bool

func IsBadRequest

func IsBadRequest(err error) bool

BAD_REQUEST Bad Request

func IsCache

func IsCache(err error) bool

func IsClientClose

func IsClientClose(err error) bool

func IsCode

func IsCode(err error, code int) bool

IsCode .

Example
err := New(http.StatusNotFound, "StatusNotFound", "StatusNotFound")
fmt.Println(IsCode(err, http.StatusNotFound))
Output:

func IsConflict

func IsConflict(err error) bool

func IsConnectionError

func IsConnectionError(err error) bool

func IsContinue

func IsContinue(err error) bool

CONTINUE Continue

func IsCreated

func IsCreated(err error) bool

func IsDb

func IsDb(err error) bool

DB database

func IsEarlyHints

func IsEarlyHints(err error) bool

func IsEmpty306

func IsEmpty306(err error) bool

func IsExpectationFailed

func IsExpectationFailed(err error) bool

func IsFailedDependency

func IsFailedDependency(err error) bool

func IsFatal

func IsFatal(err error) bool

func IsForbidden

func IsForbidden(err error) bool

func IsFound

func IsFound(err error) bool

func IsGatewayTimeout

func IsGatewayTimeout(err error) bool

func IsGone

func IsGone(err error) bool

func IsHttpVersionNotSupported

func IsHttpVersionNotSupported(err error) bool

func IsIMUsed

func IsIMUsed(err error) bool

func IsInsufficientStorage

func IsInsufficientStorage(err error) bool

func IsInternalError

func IsInternalError(err error) bool

func IsInternalServer

func IsInternalServer(err error) bool

INTERNAL_SERVER Internal Server Error

func IsInvalidParameter

func IsInvalidParameter(err error) bool

func IsKafka

func IsKafka(err error) bool

func IsLengthRequired

func IsLengthRequired(err error) bool

func IsLocked

func IsLocked(err error) bool

func IsLoopDetected

func IsLoopDetected(err error) bool

func IsMethodNotAllowed

func IsMethodNotAllowed(err error) bool

func IsMisdirectedRequest

func IsMisdirectedRequest(err error) bool

func IsMongo

func IsMongo(err error) bool

func IsMovedPermanently

func IsMovedPermanently(err error) bool

func IsMq

func IsMq(err error) bool

MQ message queue

func IsMultiStatus

func IsMultiStatus(err error) bool

func IsMultipleChoices

func IsMultipleChoices(err error) bool

MULTIPLE_CHOICES MultipleChoices

func IsMysql

func IsMysql(err error) bool

func IsNetworkAuthenticationRequired

func IsNetworkAuthenticationRequired(err error) bool

func IsNetworkError

func IsNetworkError(err error) bool

func IsNetworkTimeout

func IsNetworkTimeout(err error) bool

func IsNoContent

func IsNoContent(err error) bool

func IsNonAuthoritativeInfo

func IsNonAuthoritativeInfo(err error) bool

func IsNotAcceptable

func IsNotAcceptable(err error) bool

func IsNotExtended

func IsNotExtended(err error) bool

func IsNotFound

func IsNotFound(err error) bool

func IsNotImplemented

func IsNotImplemented(err error) bool

func IsNotModified

func IsNotModified(err error) bool

func IsOk

func IsOk(err error) bool

OK OK

func IsPanic

func IsPanic(err error) bool

func IsPartialContent

func IsPartialContent(err error) bool

func IsPaymentRequired

func IsPaymentRequired(err error) bool

func IsPermanentRedirect

func IsPermanentRedirect(err error) bool

func IsPreconditionFailed

func IsPreconditionFailed(err error) bool

func IsPreconditionRequired

func IsPreconditionRequired(err error) bool

func IsProcessing

func IsProcessing(err error) bool

func IsProxyAuthRequired

func IsProxyAuthRequired(err error) bool

func IsQueue

func IsQueue(err error) bool

func IsRabbitMq

func IsRabbitMq(err error) bool

func IsReason

func IsReason(err error, reason string) bool

IsReason .

Example
err := New(http.StatusNotFound, "StatusNotFound", "StatusNotFound")
fmt.Println(IsReason(err, "StatusNotFound"))
Output:

func IsRecordAlreadyExists

func IsRecordAlreadyExists(err error) bool

func IsRecordNotFound

func IsRecordNotFound(err error) bool

func IsRedis

func IsRedis(err error) bool

func IsRequestEntityTooLarge

func IsRequestEntityTooLarge(err error) bool

func IsRequestFailed

func IsRequestFailed(err error) bool

func IsRequestHeaderFieldsTooLarge

func IsRequestHeaderFieldsTooLarge(err error) bool

func IsRequestNotSupport

func IsRequestNotSupport(err error) bool

func IsRequestTimeout

func IsRequestTimeout(err error) bool

func IsRequestUriTooLong

func IsRequestUriTooLong(err error) bool

func IsRequestedRangeNotSatisfiable

func IsRequestedRangeNotSatisfiable(err error) bool

func IsResetContent

func IsResetContent(err error) bool

func IsSeeOther

func IsSeeOther(err error) bool

func IsServiceUnavailable

func IsServiceUnavailable(err error) bool

func IsSwitchingProtocols

func IsSwitchingProtocols(err error) bool

func IsTeapot

func IsTeapot(err error) bool

func IsTemporaryRedirect

func IsTemporaryRedirect(err error) bool

func IsThirdPartyServiceInternalError

func IsThirdPartyServiceInternalError(err error) bool

第三方服务错误

func IsThirdPartyServiceInvalidCode

func IsThirdPartyServiceInvalidCode(err error) bool

THIRD_PARTY_SERVICE_INVALID_CODE third party

func IsTooEarly

func IsTooEarly(err error) bool

func IsTooManyRequests

func IsTooManyRequests(err error) bool

func IsUnauthorized

func IsUnauthorized(err error) bool

func IsUnavailableForLegalReasons

func IsUnavailableForLegalReasons(err error) bool

func IsUnimplemented

func IsUnimplemented(err error) bool

func IsUninitialized

func IsUninitialized(err error) bool

func IsUnknown

func IsUnknown(err error) bool

UNKNOWN 常规

func IsUnprocessableEntity

func IsUnprocessableEntity(err error) bool

func IsUnsupportedMediaType

func IsUnsupportedMediaType(err error) bool

func IsUpgradeRequired

func IsUpgradeRequired(err error) bool

func IsUseProxy

func IsUseProxy(err error) bool

func IsVariantAlsoNegotiates

func IsVariantAlsoNegotiates(err error) bool

func Message

func Message(err error) string

Message returns the message for a particular error.

func Metadata

func Metadata(err error) (metadata map[string]string, ok bool)

Metadata returns the metadata for a particular error.

func NotFound

func NotFound(reason, message string, eSlice ...error) *errors.Error

NotFound mapped to a 404 response.

func NotFoundWithMetadata

func NotFoundWithMetadata(reason, message string, md map[string]string) *errors.Error

NotFoundWithMetadata mapped to a 404 response.

func NotImplemented

func NotImplemented(reason, message string, eSlice ...error) *errors.Error

NotImplemented mapped to a HTTP 501 response.

func NotImplementedWithMetadata

func NotImplementedWithMetadata(reason, message string, md map[string]string) error

NotImplementedWithMetadata mapped to a HTTP 501 response.

func Println

func Println(err error)

Println 输出错误

func Reason

func Reason(err error) string

Reason returns the reason for a particular error.

Example
err := New(http.StatusNotFound, "StatusNotFound", "StatusNotFound")
fmt.Println(Reason(err))
Output:

func RecoverStack

func RecoverStack() string

RecoverStack ...

func ServiceUnavailable

func ServiceUnavailable(reason, message string, eSlice ...error) *errors.Error

ServiceUnavailable mapped to a HTTP 503 response.

func ServiceUnavailableWithMetadata

func ServiceUnavailableWithMetadata(reason, message string, md map[string]string) *errors.Error

ServiceUnavailableWithMetadata mapped to a HTTP 503 response.

func Stack

func Stack(err error) (callers []string)

Stack 序列化调用者:file:line

func StatusOK

func StatusOK(reason, message string, eSlice ...error) *errors.Error

StatusOK 200

func StatusOKWithMetadata

func StatusOKWithMetadata(reason, message string, md map[string]string) *errors.Error

StatusOKWithMetadata 200

func TooManyRequests

func TooManyRequests(reason, message string, eSlice ...error) *errors.Error

TooManyRequests mapped to a 429 response.

func TooManyRequestsWithMetadata

func TooManyRequestsWithMetadata(reason, message string, md map[string]string) *errors.Error

TooManyRequestsWithMetadata mapped to a 409 response.

func Unauthorized

func Unauthorized(reason, message string, eSlice ...error) *errors.Error

Unauthorized mapped to a 401 response.

func UnauthorizedWithMetadata

func UnauthorizedWithMetadata(reason, message string, md map[string]string) *errors.Error

UnauthorizedWithMetadata mapped to a 401 response.

func WrapWithEnumNumber

func WrapWithEnumNumber(e *errors.Error, enum Enum) error

WrapWithEnumNumber enum number

func WrapWithMetadata

func WrapWithMetadata(e *errors.Error, md map[string]string) error

WrapWithMetadata returns an error

Types

type ERROR

type ERROR int32

ERROR .

const (
	// UNKNOWN 常规
	ERROR_UNKNOWN               ERROR = 0
	ERROR_REQUEST_FAILED        ERROR = 10001
	ERROR_RECORD_NOT_FOUND      ERROR = 10002
	ERROR_RECORD_ALREADY_EXISTS ERROR = 10003
	ERROR_NETWORK_ERROR         ERROR = 10004
	ERROR_NETWORK_TIMEOUT       ERROR = 10005
	ERROR_CONNECTION_ERROR      ERROR = 10006
	ERROR_UNINITIALIZED         ERROR = 10007
	ERROR_UNIMPLEMENTED         ERROR = 10008
	ERROR_INVALID_PARAMETER     ERROR = 10009
	ERROR_REQUEST_NOT_SUPPORT   ERROR = 10010
	ERROR_INTERNAL_ERROR        ERROR = 10011
	ERROR_PANIC                 ERROR = 10012
	ERROR_FATAL                 ERROR = 10013
	// DB database
	ERROR_DB    ERROR = 11001
	ERROR_MYSQL ERROR = 11002
	ERROR_MONGO ERROR = 11003
	ERROR_CACHE ERROR = 11004
	ERROR_REDIS ERROR = 11005
	// MQ message queue
	ERROR_MQ        ERROR = 12001
	ERROR_QUEUE     ERROR = 12002
	ERROR_RABBIT_MQ ERROR = 12003
	ERROR_KAFKA     ERROR = 12004
	// THIRD_PARTY_SERVICE_INVALID_CODE third party
	ERROR_THIRD_PARTY_SERVICE_INVALID_CODE   ERROR = 13002 // 第三方服务响应结果有误
	ERROR_THIRD_PARTY_SERVICE_INTERNAL_ERROR ERROR = 13001 // 第三方服务错误
	// CONTINUE Continue
	ERROR_CONTINUE            ERROR = 100
	ERROR_SWITCHING_PROTOCOLS ERROR = 101
	ERROR_PROCESSING          ERROR = 102
	ERROR_EARLY_HINTS         ERROR = 103
	// OK OK
	ERROR_OK                     ERROR = 200
	ERROR_CREATED                ERROR = 201
	ERROR_ACCEPTED               ERROR = 202
	ERROR_NON_AUTHORITATIVE_INFO ERROR = 203
	ERROR_NO_CONTENT             ERROR = 204
	ERROR_RESET_CONTENT          ERROR = 205
	ERROR_PARTIAL_CONTENT        ERROR = 206
	ERROR_MULTI_STATUS           ERROR = 207
	ERROR_ALREADY_REPORTED       ERROR = 208
	ERROR_I_M_USED               ERROR = 226
	// MULTIPLE_CHOICES MultipleChoices
	ERROR_MULTIPLE_CHOICES   ERROR = 300
	ERROR_MOVED_PERMANENTLY  ERROR = 301
	ERROR_FOUND              ERROR = 302
	ERROR_SEE_OTHER          ERROR = 303
	ERROR_NOT_MODIFIED       ERROR = 304
	ERROR_USE_PROXY          ERROR = 305
	ERROR_EMPTY306           ERROR = 306
	ERROR_TEMPORARY_REDIRECT ERROR = 307
	ERROR_PERMANENT_REDIRECT ERROR = 308
	// BAD_REQUEST Bad Request
	ERROR_BAD_REQUEST                     ERROR = 400
	ERROR_UNAUTHORIZED                    ERROR = 401
	ERROR_PAYMENT_REQUIRED                ERROR = 402
	ERROR_FORBIDDEN                       ERROR = 403
	ERROR_NOT_FOUND                       ERROR = 404
	ERROR_METHOD_NOT_ALLOWED              ERROR = 405
	ERROR_NOT_ACCEPTABLE                  ERROR = 406
	ERROR_PROXY_AUTH_REQUIRED             ERROR = 407
	ERROR_REQUEST_TIMEOUT                 ERROR = 408
	ERROR_CONFLICT                        ERROR = 409
	ERROR_GONE                            ERROR = 410
	ERROR_LENGTH_REQUIRED                 ERROR = 411
	ERROR_PRECONDITION_FAILED             ERROR = 412
	ERROR_REQUEST_ENTITY_TOO_LARGE        ERROR = 413
	ERROR_REQUEST_URI_TOO_LONG            ERROR = 414
	ERROR_UNSUPPORTED_MEDIA_TYPE          ERROR = 415
	ERROR_REQUESTED_RANGE_NOT_SATISFIABLE ERROR = 416
	ERROR_EXPECTATION_FAILED              ERROR = 417
	ERROR_TEAPOT                          ERROR = 418
	ERROR_MISDIRECTED_REQUEST             ERROR = 421
	ERROR_UNPROCESSABLE_ENTITY            ERROR = 422
	ERROR_LOCKED                          ERROR = 423
	ERROR_FAILED_DEPENDENCY               ERROR = 424
	ERROR_TOO_EARLY                       ERROR = 425
	ERROR_UPGRADE_REQUIRED                ERROR = 426
	ERROR_PRECONDITION_REQUIRED           ERROR = 428
	ERROR_TOO_MANY_REQUESTS               ERROR = 429
	ERROR_REQUEST_HEADER_FIELDS_TOO_LARGE ERROR = 431
	ERROR_UNAVAILABLE_FOR_LEGAL_REASONS   ERROR = 451
	ERROR_CLIENT_CLOSE                    ERROR = 499
	// INTERNAL_SERVER Internal Server Error
	ERROR_INTERNAL_SERVER                 ERROR = 500
	ERROR_NOT_IMPLEMENTED                 ERROR = 501
	ERROR_BAD_GATEWAY                     ERROR = 502
	ERROR_SERVICE_UNAVAILABLE             ERROR = 503
	ERROR_GATEWAY_TIMEOUT                 ERROR = 504
	ERROR_HTTP_VERSION_NOT_SUPPORTED      ERROR = 505
	ERROR_VARIANT_ALSO_NEGOTIATES         ERROR = 506
	ERROR_INSUFFICIENT_STORAGE            ERROR = 507
	ERROR_LOOP_DETECTED                   ERROR = 508
	ERROR_NOT_EXTENDED                    ERROR = 510
	ERROR_NETWORK_AUTHENTICATION_REQUIRED ERROR = 511
)

func (ERROR) Descriptor

func (ERROR) Descriptor() protoreflect.EnumDescriptor

func (ERROR) Enum

func (x ERROR) Enum() *ERROR

func (ERROR) EnumDescriptor deprecated

func (ERROR) EnumDescriptor() ([]byte, []int)

Deprecated: Use ERROR.Descriptor instead.

func (ERROR) Number

func (x ERROR) Number() protoreflect.EnumNumber

func (ERROR) String

func (x ERROR) String() string

func (ERROR) Type

func (ERROR) Type() protoreflect.EnumType

type Enum

type Enum interface {
	String() string
	Number() protoreflect.EnumNumber
}

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error ...

func Err

func Err(code int, e Enum, msg string) *Error

func ErrWithMetadata

func ErrWithMetadata(code int, enum Enum, message string, md map[string]string) *Error

ErrWithMetadata ...

func Errf

func Errf(code int, e Enum, format string, a ...interface{}) *Error

func Errorf

func Errorf(code int, reason, format string, a ...interface{}) *Error

Errorf returns an error object for the code, message and error info.

func New

func New(code int, reason, message string) *Error

New ...

Example
err := New(http.StatusNotFound, "StatusNotFound", "StatusNotFound")
fmt.Printf("%+v\n", err)
Output:

func NewWithMetadata

func NewWithMetadata(code int, reason, message string, md map[string]string) *Error

NewWithMetadata ...

func Newf

func Newf(code int, reason, format string, a ...interface{}) *Error

Newf New(code fmt.Sprintf(format, a...))

func WithStack

func WithStack(e *errors.Error) *Error

WithStack returns an error

func Wrap

func Wrap(e *errors.Error, eSlice ...error) *Error

Wrap returns an error

func (*Error) Cause

func (e *Error) Cause() error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Format

func (e *Error) Format(s fmt.State, verb rune)

func (*Error) GetCode

func (e *Error) GetCode() int32

func (*Error) GetMessage

func (e *Error) GetMessage() string

func (*Error) GetMetadata

func (e *Error) GetMetadata() map[string]string

func (*Error) GetReason

func (e *Error) GetReason() string

func (*Error) Message

func (e *Error) Message() string

func (*Error) StackTrace

func (e *Error) StackTrace() StackTrace

StackTrace ...

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.

func (Frame) Format

func (f Frame) Format(s fmt.State, verb rune)

Format formats the frame according to the fmt.Formatter interface.

%s    source file
%d    source line
%n    function name
%v    equivalent to %s:%d

Format accepts flags that alter the printing of some verbs, as follows:

%+s   function name and path of source file relative to the compile time
      GOPATH separated by \n\t (<funcname>\n\t<path>)
%+v   equivalent to %+s:%d

func (Frame) MarshalText

func (f Frame) MarshalText() ([]byte, error)

MarshalText formats a stacktrace Frame as a text string. The output is the same as that of fmt.Sprintf("%+v", f), but without newlines or tabs.

type StackTrace

type StackTrace []Frame

StackTrace is stack of Frames from innermost (newest) to outermost (oldest).

func (StackTrace) Format

func (st StackTrace) Format(s fmt.State, verb rune)

Format formats the stack of Frames according to the fmt.Formatter interface.

%s	lists source files for each Frame in the stack
%v	lists the source file and line number for each Frame in the stack

Format accepts flags that alter the printing of some verbs, as follows:

%+v   Prints filename, function, and line number for each Frame in the stack.

Jump to

Keyboard shortcuts

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