Documentation
¶
Index ¶
- Variables
- func GetErrorContext(err error) map[string]any
- func GetErrorDetails(err error) map[string]any
- func GetErrorMessage(err error) string
- func GetErrorStack(err error) []error
- func GetFullErrorMessage(err error) string
- func GetHTTPStatus(code ErrorCode) int
- func IsAuthenticationError(err error) bool
- func IsConflictError(err error) bool
- func IsDomainError(err error) bool
- func IsForbiddenError(err error) bool
- func IsFormError(err error) bool
- func IsNotFound(err error) bool
- func IsSystemError(err error) bool
- func IsUserError(err error) bool
- func IsValidation(err error) bool
- func UnwrapError(err error) error
- func WrapAuthenticationError(err error, message string) error
- func WrapAuthorizationError(err error, message string) error
- func WrapError(err error, code ErrorCode, message string) error
- func WrapNotFoundError(err error, message string) error
- func WrapValidationError(err error, message string) error
- type DomainError
- type ErrorCode
- type ErrorResponse
- type HTTPError
Constants ¶
This section is empty.
Variables ¶
var ( // Validation errors ErrValidation = New(ErrCodeValidation, "validation error", nil) ErrRequiredField = New(ErrCodeRequired, "field is required", nil) ErrInvalidFormat = New(ErrCodeInvalidFormat, "invalid format", nil) ErrInvalidValue = New(ErrCodeInvalid, "invalid value", nil) ErrInvalidInput = New(ErrCodeInvalidInput, "invalid input", nil) // Authentication errors ErrForbidden = New(ErrCodeForbidden, "forbidden", nil) ErrInvalidToken = New(ErrCodeInvalidToken, "invalid token", nil) ErrAuthentication = New(ErrCodeAuthentication, "authentication error", nil) ErrInsufficientRole = New(ErrCodeInsufficientRole, "insufficient role", nil) // Resource errors ErrNotFound = New(ErrCodeNotFound, "resource not found", nil) ErrConflict = New(ErrCodeConflict, "resource conflict", nil) ErrBadRequest = New(ErrCodeBadRequest, "bad request", nil) ErrServerError = New(ErrCodeServerError, "internal server error", nil) ErrAlreadyExists = New(ErrCodeAlreadyExists, "resource already exists", nil) // System errors ErrDatabase = New(ErrCodeDatabase, "database error", nil) ErrTimeout = New(ErrCodeTimeout, "operation timed out", nil) ErrConfig = New(ErrCodeConfig, "configuration error", nil) // Form-specific errors ErrFormValidation = New(ErrCodeFormValidation, "form validation error", nil) ErrFormNotFound = New(ErrCodeFormNotFound, "form not found", nil) ErrFormSubmission = New(ErrCodeFormSubmission, "form submission error", nil) ErrFormAccessDenied = New(ErrCodeFormAccessDenied, "form access denied", nil) ErrFormInvalid = New(ErrCodeFormInvalid, "invalid form", nil) ErrFormExpired = New(ErrCodeFormExpired, "form has expired", nil) // User-specific errors ErrUserNotFound = New(ErrCodeUserNotFound, "user not found", nil) ErrUserExists = New(ErrCodeUserExists, "user already exists", nil) ErrUserDisabled = New(ErrCodeUserDisabled, "user is disabled", nil) ErrUserInvalid = New(ErrCodeUserInvalid, "invalid user", nil) )
Common error instances
Functions ¶
func GetErrorContext ¶ added in v0.1.5
GetErrorContext returns the error context if the error is a DomainError
func GetErrorDetails ¶ added in v0.1.5
GetErrorDetails returns the error details if the error is a DomainError
func GetErrorMessage ¶ added in v0.1.5
GetErrorMessage returns the error message
func GetErrorStack ¶ added in v0.1.5
GetErrorStack returns the error stack if the error is a DomainError
func GetFullErrorMessage ¶ added in v0.1.5
GetFullErrorMessage returns the full error message including wrapped errors
func GetHTTPStatus ¶ added in v0.1.5
GetHTTPStatus returns the appropriate HTTP status code for an error code
func IsAuthenticationError ¶ added in v0.1.5
func IsConflictError ¶ added in v0.1.5
func IsDomainError ¶ added in v0.1.5
IsDomainError checks if the error is a domain error
func IsForbiddenError ¶ added in v0.1.5
func IsFormError ¶ added in v0.1.5
func IsSystemError ¶ added in v0.1.5
func IsUserError ¶ added in v0.1.5
func IsValidation ¶ added in v0.1.5
func UnwrapError ¶ added in v0.1.5
UnwrapError unwraps an error to its original error
func WrapAuthenticationError ¶ added in v0.1.5
WrapAuthenticationError wraps an error with an authentication error
func WrapAuthorizationError ¶ added in v0.1.5
WrapAuthorizationError wraps an error with an authorization error
func WrapNotFoundError ¶ added in v0.1.5
WrapNotFoundError wraps an error with a not found error
func WrapValidationError ¶ added in v0.1.5
WrapValidationError wraps an error with a validation error
Types ¶
type DomainError ¶
DomainError represents a domain-specific error
func GetDomainError ¶ added in v0.1.5
func GetDomainError(err error) *DomainError
GetDomainError returns the domain error if the error is a DomainError
func New ¶
func New(code ErrorCode, message string, err error) *DomainError
New creates a new domain error
func Wrap ¶
func Wrap(err error, code ErrorCode, message string) *DomainError
Wrap wraps an existing error with domain context
func WrapErrorf ¶ added in v0.1.5
func WrapErrorf(err error, code ErrorCode, format string, args ...any) *DomainError
WrapErrorf wraps an error with a formatted message
func (*DomainError) Error ¶
func (e *DomainError) Error() string
func (*DomainError) HTTPStatus ¶ added in v0.1.5
func (e *DomainError) HTTPStatus() int
HTTPStatus returns the appropriate HTTP status code for the error
func (*DomainError) ToResponse ¶ added in v0.1.5
func (e *DomainError) ToResponse() ErrorResponse
ToResponse converts the DomainError to a standardized ErrorResponse
func (*DomainError) Unwrap ¶
func (e *DomainError) Unwrap() error
func (*DomainError) WithContext ¶
func (e *DomainError) WithContext(key string, value any) *DomainError
WithContext adds context to the error
type ErrorCode ¶
type ErrorCode string
ErrorCode represents a specific type of error
const ( // Validation errors ErrCodeValidation ErrorCode = "VALIDATION_ERROR" ErrCodeRequired ErrorCode = "REQUIRED_FIELD" ErrCodeInvalid ErrorCode = "INVALID_VALUE" ErrCodeInvalidFormat ErrorCode = "INVALID_FORMAT" ErrCodeInvalidInput ErrorCode = "INVALID_INPUT" // Authentication errors ErrCodeForbidden ErrorCode = "FORBIDDEN" ErrCodeInvalidToken ErrorCode = "INVALID_TOKEN" ErrCodeAuthentication ErrorCode = "AUTHENTICATION_ERROR" ErrCodeInsufficientRole ErrorCode = "INSUFFICIENT_ROLE" // Resource errors ErrCodeNotFound ErrorCode = "NOT_FOUND" ErrCodeConflict ErrorCode = "CONFLICT" ErrCodeBadRequest ErrorCode = "BAD_REQUEST" ErrCodeServerError ErrorCode = "SERVER_ERROR" ErrCodeAlreadyExists ErrorCode = "ALREADY_EXISTS" // Application lifecycle errors ErrCodeStartup ErrorCode = "STARTUP_ERROR" ErrCodeShutdown ErrorCode = "SHUTDOWN_ERROR" ErrCodeConfig ErrorCode = "CONFIG_ERROR" ErrCodeDatabase ErrorCode = "DATABASE_ERROR" ErrCodeTimeout ErrorCode = "TIMEOUT" // Form-specific errors ErrCodeFormValidation ErrorCode = "FORM_VALIDATION_ERROR" ErrCodeFormNotFound ErrorCode = "FORM_NOT_FOUND" ErrCodeFormSubmission ErrorCode = "FORM_SUBMISSION_ERROR" ErrCodeFormAccessDenied ErrorCode = "FORM_ACCESS_DENIED" ErrCodeFormInvalid ErrorCode = "FORM_INVALID" ErrCodeFormExpired ErrorCode = "FORM_EXPIRED" // User-specific errors ErrCodeUserNotFound ErrorCode = "USER_NOT_FOUND" ErrCodeUserExists ErrorCode = "USER_EXISTS" ErrCodeUserDisabled ErrorCode = "USER_DISABLED" ErrCodeUserInvalid ErrorCode = "USER_INVALID" )
func GetErrorCode ¶ added in v0.1.5
GetErrorCode returns the error code if the error is a DomainError
type ErrorResponse ¶ added in v0.1.5
type ErrorResponse struct {
Code string `json:"code"`
Message string `json:"message"`
Details map[string]any `json:"details,omitempty"`
}
ErrorResponse represents a standardized error response for HTTP handlers
type HTTPError ¶ added in v0.2.0
type HTTPError struct {
Code int `json:"code"`
Message string `json:"message"`
Details map[string]any `json:"details,omitempty"`
}
HTTPError represents an HTTP error response
func NewHTTPError ¶ added in v0.2.0
NewHTTPError creates a new HTTP error
func TranslateToHTTP ¶ added in v0.2.0
TranslateToHTTP translates a domain error to an HTTP error