Documentation
¶
Index ¶
- Constants
- Variables
- func GetErrorCode(err error) string
- func GetHTTPStatus(err error) int
- func IsAppError(err error) bool
- type AppError
- func GetAppError(err error) *AppError
- func NewBadRequestError(message string) *AppError
- func NewConfigurationError(message string) *AppError
- func NewConflictError(message string) *AppError
- func NewDatabaseError(op string, err error) *AppError
- func NewForbiddenError(message string) *AppError
- func NewInsufficientRoleError(required, actual string) *AppError
- func NewInternalError(message string) *AppError
- func NewNotFoundError(resource string) *AppError
- func NewRateLimitedError() *AppError
- func NewTokenExpiredError() *AppError
- func NewTokenInvalidError(reason string) *AppError
- func NewUnauthorizedError(message string) *AppError
- func NewValidationError(message string) *AppError
Constants ¶
const ( CodeForbidden = "FORBIDDEN" CodeNotFound = "NOT_FOUND" CodeBadRequest = "BAD_REQUEST" CodeInternalError = "INTERNAL_ERROR" CodeValidation = "VALIDATION_ERROR" CodeConflict = "CONFLICT" CodeRateLimited = "RATE_LIMITED" CodeTokenExpired = "TOKEN_EXPIRED" CodeTokenInvalid = "TOKEN_INVALID" CodeInsufficientRole = "INSUFFICIENT_ROLE" CodeResourceNotOwned = "RESOURCE_NOT_OWNED" CodeDatabaseError = "DATABASE_ERROR" CodeConfigurationError = "CONFIGURATION_ERROR" )
Standard error codes
Variables ¶
var ( ErrForbidden = NewForbiddenError("access denied") ErrTokenExpired = NewTokenExpiredError() ErrInvalidCredentials = NewUnauthorizedError("invalid credentials") ErrRateLimited = NewRateLimitedError() )
Sentinel errors for common cases
Functions ¶
func GetErrorCode ¶
GetErrorCode returns the error code for an error
func GetHTTPStatus ¶
GetHTTPStatus returns the HTTP status code for an error
Types ¶
type AppError ¶
type AppError struct {
// Code is the error code for programmatic handling
Code string `json:"code"`
// Message is the human-readable error message
Message string `json:"message"`
// HTTPStatus is the HTTP status code to return
HTTPStatus int `json:"-"`
// Op is the operation that failed
Op string `json:"-"`
// Err is the underlying error
Err error `json:"-"`
// Details contains additional error context
Details map[string]interface{} `json:"details,omitempty"`
}
AppError represents an application error with context
func GetAppError ¶
GetAppError extracts AppError from an error chain
func NewBadRequestError ¶
NewBadRequestError creates a bad request error
func NewConfigurationError ¶
NewConfigurationError creates a configuration error
func NewConflictError ¶
NewConflictError creates a conflict error
func NewDatabaseError ¶
NewDatabaseError creates a database error
func NewForbiddenError ¶
NewForbiddenError creates a forbidden error
func NewInsufficientRoleError ¶
NewInsufficientRoleError creates an insufficient role error
func NewInternalError ¶
NewInternalError creates an internal server error
func NewNotFoundError ¶
NewNotFoundError creates a not found error
func NewRateLimitedError ¶
func NewRateLimitedError() *AppError
NewRateLimitedError creates a rate limited error
func NewTokenExpiredError ¶
func NewTokenExpiredError() *AppError
NewTokenExpiredError creates a token expired error
func NewTokenInvalidError ¶
NewTokenInvalidError creates a token invalid error
func NewUnauthorizedError ¶
NewUnauthorizedError creates an unauthorized error
func NewValidationError ¶
NewValidationError creates a validation error
func (*AppError) WithDetails ¶
WithDetails adds additional context details