Documentation
¶
Index ¶
- Variables
- func AddDetail(err error, key string, value interface{}) error
- func AddDetails(err error, details map[string]interface{}) error
- func BenchmarkAddDetail(b *testing.B)
- func BenchmarkAddDetailMultiple(b *testing.B)
- func BenchmarkAddDetails(b *testing.B)
- func BenchmarkErrorCodeCategorizer_Categorize(b *testing.B)
- func BenchmarkErrorCodeCategorizer_IsClientError(b *testing.B)
- func BenchmarkErrorCodeCategorizer_IsExternalError(b *testing.B)
- func BenchmarkErrorCodeCategorizer_IsSecurityError(b *testing.B)
- func BenchmarkErrorCodeCategorizer_IsServerError(b *testing.B)
- func BenchmarkErrorCodeCategorizer_IsSystemError(b *testing.B)
- func BenchmarkErrorCodeGrouper_Group(b *testing.B)
- func BenchmarkErrorCodeGrouper_IsBusinessError(b *testing.B)
- func BenchmarkErrorCodeGrouper_IsExternalError(b *testing.B)
- func BenchmarkErrorCodeGrouper_IsInputError(b *testing.B)
- func BenchmarkErrorCodeGrouper_IsResourceError(b *testing.B)
- func BenchmarkErrorCodeGrouper_IsSecurityError(b *testing.B)
- func BenchmarkErrorCodeGrouper_IsSystemError(b *testing.B)
- func BenchmarkErrorCodeMapper_ToCategory(b *testing.B)
- func BenchmarkErrorCodeMapper_ToCategoryInvalidCode(b *testing.B)
- func BenchmarkErrorCodeMapper_ToHTTPStatus(b *testing.B)
- func BenchmarkErrorCodeMapper_ToHTTPStatusInvalidCode(b *testing.B)
- func BenchmarkErrorCodeMapper_ToMessage(b *testing.B)
- func BenchmarkErrorCodeMapper_ToMessageInvalidCode(b *testing.B)
- func BenchmarkGetDetail(b *testing.B)
- func BenchmarkGetDetails(b *testing.B)
- func BenchmarkValidator_GetCodeName(b *testing.B)
- func BenchmarkValidator_GetCodeName_Invalid(b *testing.B)
- func BenchmarkValidator_IsValid(b *testing.B)
- func BenchmarkValidator_Validate(b *testing.B)
- func BenchmarkValidator_Validate_Invalid(b *testing.B)
- func FromJSON(jsonStr string) (error, error)
- func GetCallerPackage(skip int) string
- func GetDetail(err error, key string) (interface{}, bool)
- func GetDetails(err error) map[string]interface{}
- func IsValid(code core.ErrorCode) bool
- func ToJSON(err error) string
- type ErrorCodeCategorizer
- func (c *ErrorCodeCategorizer) Categorize(code core.ErrorCode) ErrorCodeCategory
- func (c *ErrorCodeCategorizer) IsClientError(code core.ErrorCode) bool
- func (c *ErrorCodeCategorizer) IsExternalError(code core.ErrorCode) bool
- func (c *ErrorCodeCategorizer) IsSecurityError(code core.ErrorCode) bool
- func (c *ErrorCodeCategorizer) IsServerError(code core.ErrorCode) bool
- func (c *ErrorCodeCategorizer) IsSystemError(code core.ErrorCode) bool
- type ErrorCodeCategory
- type ErrorCodeGroup
- type ErrorCodeGrouper
- func (g *ErrorCodeGrouper) Group(code core.ErrorCode) ErrorCodeGroup
- func (g *ErrorCodeGrouper) IsBusinessError(code core.ErrorCode) bool
- func (g *ErrorCodeGrouper) IsExternalError(code core.ErrorCode) bool
- func (g *ErrorCodeGrouper) IsInputError(code core.ErrorCode) bool
- func (g *ErrorCodeGrouper) IsResourceError(code core.ErrorCode) bool
- func (g *ErrorCodeGrouper) IsSecurityError(code core.ErrorCode) bool
- func (g *ErrorCodeGrouper) IsSystemError(code core.ErrorCode) bool
- type ErrorCodeValidator
Constants ¶
This section is empty.
Variables ¶
var ErrorCodeMapper = struct { // ToHTTPStatus returns the HTTP status code for an error code ToHTTPStatus func(code core.ErrorCode) int // ToCategory returns the category for an error code ToCategory func(code core.ErrorCode) string // ToMessage returns a user-friendly message for an error code ToMessage func(code core.ErrorCode) string }{ ToHTTPStatus: func(code core.ErrorCode) int { return core.GetHTTPStatus(code) }, ToCategory: func(code core.ErrorCode) string { switch code { case core.NotFoundCode, core.InvalidInputCode, core.AlreadyExistsCode, core.ResourceExhaustedCode, core.ValidationErrorCode, core.BusinessRuleViolationCode: return "Client" case core.DatabaseErrorCode, core.InternalErrorCode, core.DataCorruptionCode, core.ConfigurationErrorCode: return "Server" case core.TimeoutCode, core.CanceledCode, core.ConcurrencyErrorCode: return "System" case core.ExternalServiceErrorCode, core.NetworkErrorCode: return "External" case core.UnauthorizedCode, core.ForbiddenCode: return "Security" default: return "Unknown" } }, ToMessage: func(code core.ErrorCode) string { switch code { case core.NotFoundCode: return "The requested resource was not found" case core.InvalidInputCode: return "The provided input is invalid" case core.DatabaseErrorCode: return "A database operation failed" case core.InternalErrorCode: return "An internal server error occurred" case core.TimeoutCode: return "The operation timed out" case core.CanceledCode: return "The operation was canceled" case core.AlreadyExistsCode: return "The resource already exists" case core.UnauthorizedCode: return "Authentication failed" case core.ForbiddenCode: return "Access is forbidden" case core.ValidationErrorCode: return "Input validation failed" case core.BusinessRuleViolationCode: return "A business rule was violated" case core.ExternalServiceErrorCode: return "An external service call failed" case core.NetworkErrorCode: return "A network error occurred" case core.ConfigurationErrorCode: return "Configuration error" case core.ResourceExhaustedCode: return "Resource limit reached" case core.DataCorruptionCode: return "Data corruption detected" case core.ConcurrencyErrorCode: return "Concurrency violation" default: return "An unknown error occurred" } }, }
ErrorCodeMapper maps error codes to various representations
Functions ¶
func AddDetails ¶
AddDetails adds multiple details to an error's context
func BenchmarkAddDetail ¶
func BenchmarkAddDetails ¶
func BenchmarkGetDetail ¶
func BenchmarkGetDetails ¶
func GetCallerPackage ¶
GetCallerPackage returns the package name of the caller.
func GetDetails ¶
GetDetails retrieves all details from an error's context
Types ¶
type ErrorCodeCategorizer ¶
type ErrorCodeCategorizer struct {
// contains filtered or unexported fields
}
ErrorCodeCategorizer categorizes error codes
func NewErrorCodeCategorizer ¶
func NewErrorCodeCategorizer() *ErrorCodeCategorizer
NewErrorCodeCategorizer creates a new error code categorizer
func (*ErrorCodeCategorizer) Categorize ¶
func (c *ErrorCodeCategorizer) Categorize(code core.ErrorCode) ErrorCodeCategory
Categorize returns the category of an error code
func (*ErrorCodeCategorizer) IsClientError ¶
func (c *ErrorCodeCategorizer) IsClientError(code core.ErrorCode) bool
IsClientError returns true if the error code is a client error
func (*ErrorCodeCategorizer) IsExternalError ¶
func (c *ErrorCodeCategorizer) IsExternalError(code core.ErrorCode) bool
IsExternalError returns true if the error code is an external error
func (*ErrorCodeCategorizer) IsSecurityError ¶
func (c *ErrorCodeCategorizer) IsSecurityError(code core.ErrorCode) bool
IsSecurityError returns true if the error code is a security error
func (*ErrorCodeCategorizer) IsServerError ¶
func (c *ErrorCodeCategorizer) IsServerError(code core.ErrorCode) bool
IsServerError returns true if the error code is a server error
func (*ErrorCodeCategorizer) IsSystemError ¶
func (c *ErrorCodeCategorizer) IsSystemError(code core.ErrorCode) bool
IsSystemError returns true if the error code is a system error
type ErrorCodeCategory ¶
type ErrorCodeCategory string
ErrorCodeCategory represents a category of error codes
const ( // ClientError indicates an error caused by client input ClientError ErrorCodeCategory = "CLIENT_ERROR" // ServerError indicates an error caused by server-side issues ServerError ErrorCodeCategory = "SERVER_ERROR" // SystemError indicates an error caused by system-level issues SystemError ErrorCodeCategory = "SYSTEM_ERROR" // ExternalError indicates an error caused by external systems ExternalError ErrorCodeCategory = "EXTERNAL_ERROR" // SecurityError indicates a security-related error SecurityError ErrorCodeCategory = "SECURITY_ERROR" )
type ErrorCodeGroup ¶
type ErrorCodeGroup string
ErrorCodeGroup represents a group of related error codes
const ( // ResourceGroup contains resource-related errors ResourceGroup ErrorCodeGroup = "RESOURCE" // InputGroup contains input validation errors InputGroup ErrorCodeGroup = "INPUT" // SystemGroup contains system-level errors SystemGroup ErrorCodeGroup = "SYSTEM" // SecurityGroup contains security-related errors SecurityGroup ErrorCodeGroup = "SECURITY" // ExternalGroup contains external system errors ExternalGroup ErrorCodeGroup = "EXTERNAL" // BusinessGroup contains business rule errors BusinessGroup ErrorCodeGroup = "BUSINESS" )
type ErrorCodeGrouper ¶
type ErrorCodeGrouper struct {
// contains filtered or unexported fields
}
ErrorCodeGrouper groups error codes
func NewErrorCodeGrouper ¶
func NewErrorCodeGrouper() *ErrorCodeGrouper
NewErrorCodeGrouper creates a new error code grouper
func (*ErrorCodeGrouper) Group ¶
func (g *ErrorCodeGrouper) Group(code core.ErrorCode) ErrorCodeGroup
Group returns the group of an error code
func (*ErrorCodeGrouper) IsBusinessError ¶
func (g *ErrorCodeGrouper) IsBusinessError(code core.ErrorCode) bool
IsBusinessError returns true if the error code is a business error
func (*ErrorCodeGrouper) IsExternalError ¶
func (g *ErrorCodeGrouper) IsExternalError(code core.ErrorCode) bool
IsExternalError returns true if the error code is an external error
func (*ErrorCodeGrouper) IsInputError ¶
func (g *ErrorCodeGrouper) IsInputError(code core.ErrorCode) bool
IsInputError returns true if the error code is an input error
func (*ErrorCodeGrouper) IsResourceError ¶
func (g *ErrorCodeGrouper) IsResourceError(code core.ErrorCode) bool
IsResourceError returns true if the error code is a resource error
func (*ErrorCodeGrouper) IsSecurityError ¶
func (g *ErrorCodeGrouper) IsSecurityError(code core.ErrorCode) bool
IsSecurityError returns true if the error code is a security error
func (*ErrorCodeGrouper) IsSystemError ¶
func (g *ErrorCodeGrouper) IsSystemError(code core.ErrorCode) bool
IsSystemError returns true if the error code is a system error
type ErrorCodeValidator ¶
type ErrorCodeValidator struct { }
ErrorCodeValidator validates error codes
func NewErrorCodeValidator ¶
func NewErrorCodeValidator() *ErrorCodeValidator
NewErrorCodeValidator creates a new error code validator
func (*ErrorCodeValidator) GetCodeName ¶
func (v *ErrorCodeValidator) GetCodeName(code core.ErrorCode) string
GetCodeName returns the human-readable name of an error code