Documentation
¶
Index ¶
- Constants
- Variables
- func EnrichWithCtx(ctx context.Context, ae *AppError)
- func GetHTTPStatusCode(code ErrorCode) int
- func GetSrcFromCtx(ctx context.Context) string
- func GetStackTrace() string
- func IsAuthErrorCode(code ErrorCode) bool
- func IsForbiddenErrorCode(code ErrorCode) bool
- func IsSameError(err error, code ErrorCode) bool
- func IsServerErrorCode(code ErrorCode) bool
- func Raise(ctx context.Context, code ErrorCode, msg string, errToWrap error, ...) error
- func RaiseInternal(ctx context.Context, msg string, errToWrap error, extraData common.ExtraData) error
- func RaiseToSentry(ctx context.Context, err error)
- func RecoverPanic(msg string) func()
- func SetSrcInCtx(ctx context.Context, src string) context.Context
- type AppError
- func (ae *AppError) AddExtraData(key string, val any)
- func (ae *AppError) Error() string
- func (ae *AppError) Format(s fmt.State, verb rune)
- func (ae *AppError) GetCode() string
- func (ae *AppError) GetErrorCode() ErrorCode
- func (ae *AppError) GetExtraData() common.ExtraData
- func (ae *AppError) GetMessage() string
- func (ae *AppError) Unwrap() error
- type ErrorCode
Constants ¶
const (
PgErrDuplicateKey = "23505"
)
postgres error codes
const ( // SVC prefix for error codes SVC string = "API" )
Variables ¶
var AuthErrorCodes = map[ErrorCode]struct{}{ ErrTokenExpiredInvalid: {}, ErrAuthInvalidCredentials: {}, ErrAuthMissingToken: {}, }
Map of auth error codes
var ForbiddenErrorCodes = map[ErrorCode]struct{}{ ErrAuthMaxSessionsReached: {}, ErrAuthPasswordResetDisabled: {}, ErrUserInsufficentRole: {}, ErrTeamRequired: {}, ErrAuthUserBanned: {}, }
Map of forbidden error codes
var ServerErrorCodes = map[ErrorCode]struct{}{ ErrInternalError: {}, ErrCacheCallFail: {}, ErrMarshalError: {}, ErrUnmarshalError: {}, ErrDBCreateError: {}, ErrDBReadError: {}, ErrDBUpdateError: {}, ErrDBExecError: {}, ErrDBDeleteError: {}, ErrCacheScriptLoadFail: {}, ErrTokenSigningFailed: {}, ErrConfigVarInvalid: {}, ErrConfigVarRefreshFailed: {}, ErrSMTPQueueFull: {}, ErrSMTPContextCanceled: {}, ErrEmailInvalidType: {}, ErrEmailTemplateFetch: {}, ErrEmailTemplateExecute: {}, ErrEmailLinkBuild: {}, ErrScoreUpdateFailed: {}, ErrCacheZSetMissingMember: {}, ErrInstanceCreationFailed: {}, ErrK8sConnectionFailed: {}, ErrInstanceInvalid: {}, ErrChallengeNameInvalid: {}, ErrInstanceUpdateFailed: {}, ErrManifestNotFound: {}, ErrInstanceDeletionFailed: {}, }
Map of server-side error codes that need to be filtered
Functions ¶
func EnrichWithCtx ¶
Sets `ExtraData` from context in the app error
func GetHTTPStatusCode ¶
func GetSrcFromCtx ¶
Extracts `Src` from the given context
func IsAuthErrorCode ¶
IsAuthErrorCode checks if the error is an auth error
func IsForbiddenErrorCode ¶
IsForbiddenErrorCode checks if the error is a forbidden error
func IsSameError ¶
IsSameError checks if the error is the same as the given ErrorCode
func IsServerErrorCode ¶
IsServerErrorCode checks if the error is a server-side error
func Raise ¶
func Raise(ctx context.Context, code ErrorCode, msg string, errToWrap error, extraData common.ExtraData) error
Raise is a general util to construct domain errors
func RaiseInternal ¶
func RaiseInternal(ctx context.Context, msg string, errToWrap error, extraData common.ExtraData) error
RaiseInternal raises an internal error
func RaiseToSentry ¶
RaiseToSentry raises the error to Sentry
func RecoverPanic ¶
func RecoverPanic(msg string) func()
RecoverPanic can be deferred to capture and log a panic
Types ¶
type AppError ¶
type AppError struct {
ErrorCode ErrorCode // unique error code
Message string // optional human-readable message
Cause error // wrapped error
ExtraData common.ExtraData // extra data associated with the error
}
AppError represents an application error with a code, message, cause, and extra data
func AsAppError ¶
AsAppError tries to cast the given error to an AppError
func (*AppError) AddExtraData ¶
func (*AppError) GetErrorCode ¶
func (*AppError) GetExtraData ¶
func (*AppError) GetMessage ¶
type ErrorCode ¶
type ErrorCode string
ErrorCode type
const ( // System errors ErrInternalError ErrorCode = "SYS-00" ErrMarshalError ErrorCode = "SYS-01" ErrUnmarshalError ErrorCode = "SYS-02" // Validation errors ErrValidationFailed ErrorCode = "VAL-00" // Rest errors ErrRestInvalidPayload ErrorCode = "REST-00" ErrRestMissingToken ErrorCode = "REST-01" ErrRestTimedOut ErrorCode = "REST-02" // User errors ErrUserInvalidRole ErrorCode = "USER-00" ErrUserEmailTaken ErrorCode = "USER-01" ErrUserUsernameTaken ErrorCode = "USER-02" ErrUserNotFound ErrorCode = "USER-03" ErrUserInsufficentRole ErrorCode = "USER-04" // Team errors ErrTeamRequired ErrorCode = "TEAM-00" ErrTeamAlreadyJoined ErrorCode = "TEAM-01" ErrTeamNameTaken ErrorCode = "TEAM-02" ErrTeamNotFound ErrorCode = "TEAM-03" ErrTeamFull ErrorCode = "TEAM-04" // DB errors ErrDBCreateError ErrorCode = "DB-00" ErrDBReadError ErrorCode = "DB-01" ErrDBUpdateError ErrorCode = "DB-02" ErrDBExecError ErrorCode = "DB-03" ErrDBDeleteError ErrorCode = "DB-04" // Cache errors ErrCacheCallFail ErrorCode = "CACHE-00" ErrCacheMiss ErrorCode = "CACHE-01" ErrCacheScriptLoadFail ErrorCode = "CACHE-02" ErrCacheZSetMissingMember ErrorCode = "CACHE-03" // Token errors ErrTokenMalformed ErrorCode = "TOKEN-00" ErrTokenExpiredInvalid ErrorCode = "TOKEN-01" ErrTokenSigningFailed ErrorCode = "TOKEN-02" // ConfigVar errors ErrConfigVarInvalid ErrorCode = "CONFIGVAR-00" ErrConfigVarRefreshFailed ErrorCode = "CONFIGVAR-01" // SMTP errors ErrSMTPDialError ErrorCode = "SMTP-00" ErrSMTPQueueFull ErrorCode = "SMTP-01" ErrSMTPMaxRetriesExceeded ErrorCode = "SMTP-02" ErrSMTPSendFailed ErrorCode = "SMTP-03" ErrSMTPContextCanceled ErrorCode = "SMTP-04" // Email errors ErrEmailInvalidType ErrorCode = "EMAIL-00" ErrEmailTemplateFetch ErrorCode = "EMAIL-01" ErrEmailTemplateExecute ErrorCode = "EMAIL-02" ErrEmailLinkBuild ErrorCode = "EMAIL-03" // Auth errors ErrAuthInvalidCredentials ErrorCode = "AUTH-00" ErrAuthMaxSessionsReached ErrorCode = "AUTH-01" ErrAuthPasswordResetDisabled ErrorCode = "AUTH-02" ErrAuthMissingToken ErrorCode = "AUTH-03" ErrAuthUserBanned ErrorCode = "AUTH-04" // Challenge errors ErrChallengeNotFound ErrorCode = "CHALLENGE-00" ErrChallengeAlreadySolved ErrorCode = "CHALLENGE-01" ErrChallengeMaxAttemptsReached ErrorCode = "CHALLENGE-02" ErrChallengeNameInvalid ErrorCode = "CHALLENGE-03" // Hint errors ErrHintNotFound ErrorCode = "HINT-00" ErrHintCostExceeded ErrorCode = "HINT-01" ErrHintAlreadyUnlocked ErrorCode = "HINT-02" // Scoreboard errors ErrScoreUpdateFailed ErrorCode = "SCORE-00" // Instance errors ErrInstanceNotOnDemand ErrorCode = "INSTANCE-00" ErrInstanceNotFound ErrorCode = "INSTANCE-01" ErrInstanceWIP ErrorCode = "INSTANCE-02" ErrInstanceAlreadyRunning ErrorCode = "INSTANCE-03" ErrInstanceCreationFailed ErrorCode = "INSTANCE-04" ErrInstanceInvalid ErrorCode = "INSTANCE-05" ErrInstanceInvalidResourceQuantity ErrorCode = "INSTANCE-06" ErrInstanceExtensionNotAllowed ErrorCode = "INSTANCE-07" ErrInstanceUpdateFailed ErrorCode = "INSTANCE-08" ErrInstanceDeletionFailed ErrorCode = "INSTANCE-09" ErrInstanceInvalidState ErrorCode = "INSTANCE-10" ErrInstanceNotRunning ErrorCode = "INSTANCE-11" // k8s errors ErrK8sConnectionFailed ErrorCode = "K8S-00" // Manifest errors ErrManifestNotFound ErrorCode = "MANIFEST-00" )
Error codes
func ExtractErrorCode ¶
ExtractErrorCode extracts the ErrorCode from an error, if it is an AppError