Files
gohoarder/pkg/errors/codes.go
T
lukaszraczylo 6b037a92b4 refactor: reorganize struct fields, add new handlers and storage backends
- [x] Reorder struct fields across codebase for consistency
- [x] Add analytics event handlers and tests
- [x] Add authentication API key management handlers and tests
- [x] Add pre-warming control handlers and tests
- [x] Implement S3 storage backend with tests
- [x] Implement SMB/CIFS storage backend with tests
- [x] Add CDN middleware tests
- [x] Integrate analytics tracking into cache manager
- [x] Add S3 and SMB storage initialization in app setup
- [x] Add CDN caching to proxy handlers
- [x] Remove distributed locking (Redis lock manager)
- [x] Remove proxy common package and utilities
- [x] Remove standalone HTTP server package
- [x] Remove logger middleware
- [x] Simplify error handling utilities
- [x] Update config with S3 and SMB options
- [x] Update cache manager signature to include analytics
2026-01-03 00:18:58 +00:00

61 lines
2.1 KiB
Go

package errors
// Error codes following consistent naming convention
const (
// Client errors (4xx)
ErrCodeBadRequest = "BAD_REQUEST"
ErrCodeUnauthorized = "UNAUTHORIZED"
ErrCodeForbidden = "FORBIDDEN"
ErrCodeNotFound = "NOT_FOUND"
ErrCodeRateLimited = "RATE_LIMITED"
ErrCodePayloadTooLarge = "PAYLOAD_TOO_LARGE"
ErrCodeInvalidAPIKey = "INVALID_API_KEY" // #nosec G101 -- Not a credential, just an error code constant
ErrCodeQuotaExceeded = "QUOTA_EXCEEDED"
ErrCodeConflict = "CONFLICT"
ErrCodeInvalidConfig = "INVALID_CONFIG"
// Package-specific errors
ErrCodePackageNotFound = "PACKAGE_NOT_FOUND"
ErrCodeVersionNotFound = "VERSION_NOT_FOUND"
ErrCodeChecksumMismatch = "CHECKSUM_MISMATCH"
ErrCodeCorruptPackage = "CORRUPT_PACKAGE"
ErrCodeSecurityBlocked = "SECURITY_BLOCKED"
ErrCodeSecurityViolation = "SECURITY_VIOLATION" // Package has vulnerabilities exceeding thresholds
ErrCodeUpstreamError = "UPSTREAM_ERROR"
// Server errors (5xx)
ErrCodeInternalServer = "INTERNAL_SERVER_ERROR"
ErrCodeStorageFailure = "STORAGE_FAILURE"
ErrCodeUpstreamFailure = "UPSTREAM_FAILURE"
ErrCodeDatabaseFailure = "DATABASE_FAILURE"
ErrCodeServiceUnavailable = "SERVICE_UNAVAILABLE"
ErrCodeCircuitOpen = "CIRCUIT_OPEN"
)
// HTTPStatusCode maps error codes to HTTP status codes
var HTTPStatusCode = map[string]int{
ErrCodeBadRequest: 400,
ErrCodeUnauthorized: 401,
ErrCodeForbidden: 403,
ErrCodeNotFound: 404,
ErrCodeConflict: 409,
ErrCodeRateLimited: 429,
ErrCodePayloadTooLarge: 413,
ErrCodeInvalidAPIKey: 401,
ErrCodeQuotaExceeded: 429,
ErrCodeInvalidConfig: 400,
ErrCodePackageNotFound: 404,
ErrCodeVersionNotFound: 404,
ErrCodeChecksumMismatch: 422,
ErrCodeCorruptPackage: 422,
ErrCodeSecurityBlocked: 403,
ErrCodeSecurityViolation: 426, // Upgrade Required
ErrCodeUpstreamError: 502,
ErrCodeInternalServer: 500,
ErrCodeStorageFailure: 500,
ErrCodeUpstreamFailure: 502,
ErrCodeDatabaseFailure: 500,
ErrCodeServiceUnavailable: 503,
ErrCodeCircuitOpen: 503,
}